Step 4: using the button and form layout of lwuit

Source: Internet
Author: User
This article from: http://blog.csdn.net/hellogv/, reprint must indicate the source!
Borderlayout divides the form layout into five parts: east, south, west, north, and center.
// Boxlayout-X, that is, the control is arranged from left to right
// Boxlayout-y, that is, the control is arranged from top to bottom
// Flowlayout: controls are arranged in rows. If one row cannot be installed, the controls are placed in the second row ......
// Gridlayout !!!!!

Lwuit requires the form and any controls to be used to set the form layout. OK. Now let's look back at the previous IMPLEMENTATION OF THE jiugong diagram. Its principle is as follows: in essence, the nine buttons are arranged according to gridlayout, And the buttons are attached with icons, in addition, when the button gets the focus (Button switching), the special effect is displayed.
Friends who have used j2se GUI should be familiar with them. Friends who have not been familiar with j2se GUI may need some time to digest them.
OK. The following code is also modified from the sample. If it is redundant, it will not be mentioned:

  1. /*
  2. * Copyright? 2008 Sun Microsystems, Inc. All rights reserved.
  3. * Use is subject to license terms.
  4. *
  5. */
  6. Package com. Sun. lwuit. uidemo;
  7. Import com. Sun. lwuit. Button;
  8. Import com. Sun. lwuit. form;
  9. Import com. Sun. lwuit. Events. actionevent;
  10. Import com. Sun. lwuit. Events. actionlistener;
  11. Import com. Sun. lwuit. layouts. borderlayout;
  12. Import com. Sun. lwuit. layouts. boxlayout;
  13. Import com. Sun. lwuit. layouts. flowlayout;
  14. Import com. Sun. lwuit. layouts. gridlayout;
  15. /**
  16. * This example shows how to layout A Form Control.
  17. */
  18. Public class layoutdemo implements actionlistener {
  19. Public form = new form ("layoutdemo ");
  20. Private button border;
  21. Private button boxy;
  22. Private button Boxx;
  23. Private button flow;
  24. Private button grid;
  25. Layoutdemo (){
  26. Form. setlayout (New boxlayout (boxlayout. y_axis ));
  27. // Borderlayout divides the form layout into five parts: east, south, west, north, and center.
  28. Border = new button ("borderlayout ");
  29. // Set the transparency of the button background in the range of 0 ~ 255. You can use the util resource editor to pre-Modify
  30. Border. getstyle (). setbgtransparency (100 );
  31. // Each button needs to design a listener event
  32. Border. addactionlistener (this );
  33. // Boxlayout-y, that is, the control is arranged from top to bottom
  34. Boxy = new button ("boxlayout-y ");
  35. Boxy. getstyle (). setbgtransparency (100 );
  36. Boxy. addactionlistener (this );
  37. // Boxlayout-X, that is, the control is arranged from left to right
  38. Boxx = new button ("boxlayout-X ");
  39. Boxx. getstyle (). setbgtransparency (100 );
  40. Boxx. addactionlistener (this );
  41. // Flowlayout: controls are arranged in rows. If one row cannot be installed, the controls are placed in the second row ......
  42. Flow = new button ("flowlayout ");
  43. Flow. getstyle (). setbgtransparency (100 );
  44. Flow. addactionlistener (this );
  45. // Gridlayout !!!!!
  46. Grid = new button ("gridlayout ");
  47. Grid. getstyle (). setbgtransparency (100 );
  48. Grid. addactionlistener (this );
  49. Addcomponents (form );
  50. Form. Show ();
  51. }
  52. Private void addcomponents (final form F ){
  53. F. removeall ();
  54. F. addcomponent (boxy );
  55. F. addcomponent (Boxx );
  56. F. addcomponent (Border );
  57. F. addcomponent (flow );
  58. F. addcomponent (GRID );
  59. }
  60. Public void actionreceivmed (actionevent arg0 ){
  61. String button_name = (button) (arg0.getsource (). gettext ();
  62. If (button_name.equals ("borderlayout "))
  63. {
  64. Form. setlayout (New borderlayout ());
  65. Form. removeall ();
  66. Form. setscrollable (false );
  67. Form. addcomponent (borderlayout. North, border );
  68. Form. addcomponent (borderlayout. East, boxy );
  69. Form. addcomponent (borderlayout. Center, grid );
  70. Form. addcomponent (borderlayout. West, flow );
  71. Form. addcomponent (borderlayout. South, Boxx );
  72. Form. Show ();
  73. }
  74. Else if (button_name.equals ("boxlayout-y "))
  75. {
  76. Form. setlayout (New boxlayout (boxlayout. y_axis ));
  77. Form. setscrollable (false );
  78. Addcomponents (form );
  79. Form. Show ();
  80. }
  81. Else if (button_name.equals ("flowlayout "))
  82. {
  83. Form. setlayout (New flowlayout ());
  84. Form. setscrollable (false );
  85. Addcomponents (form );
  86. Form. Show ();
  87. }
  88. Else if (button_name.equals ("gridlayout "))
  89. {
  90. Form. setlayout (New gridlayout (3, 2 ));
  91. Form. setscrollable (false );
  92. Addcomponents (form );
  93. Form. Show ();
  94. }
  95. Else if (button_name.equals ("boxlayout-X "))
  96. {
  97. Form. setlayout (New boxlayout (boxlayout. x_axis ));
  98. Form. setscrollable (true );
  99. Addcomponents (form );
  100. Form. Show ();
  101. }
  102. }
  103. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.