1 /*Example Name: FlowLayout Usage Example2 * source file name: Testflowlayout.java3 * Key points:4 * 1. Concept and role of layout manager5 * 2. The nature and usage of FlowLayout6 */7 8 Importjava.awt.*;9 Ten Public classTestflowlayout { One Public Static voidMain (String args[]) { AFrame f =NewFrame ("Flow Layout"); -Button button1 =Newbutton ("OK"); -Button button2 =NewButton ("Open"); theButton Button3 =NewButton ("Close"); -F.setlayout (NewFlowLayout (Flowlayout.left)); - F.add (button1); - F.add (button2); + F.add (button3); -F.setsize (100,100); +F.setvisible (true); A } at}
1 Importjava.awt.*;2 Public classTestFlowLayout2 {3 Public Static voidMain (String args[]) {4Frame f =NewFRAME ("Java frame");5FlowLayout L =6 NewFlowLayout (Flowlayout.center, 20, 40);7 f.setlayout (l);8F.setlocation (300,400);9F.setsize (300,200);TenF.setbackground (NewColor (204,204,255)); One for(inti = 1; i<=7; i++){ AF.add (NewButton ("button")); - } -F.setvisible (true); the } -}
1 /*Example Name: BorderLayout Application Example2 * source file name: Testborderlayout.java3 * Key: FlowLayout layout manager's nature and usage4 */5 6 Importjava.awt.*;7 Public classTestborderlayout {8 Public Static voidMain (String args[]) {9 Frame F;Tenf =NewFrame ("Border Layout"); OneButton bn =NewButton ("BN"); AButton bs =NewButton ("BS"); -Button bw =NewButton ("BW"); -Button be =NewButton ("Be"); theButton BC =NewButton ("BC"); - -F.add (BN, "North"); -F.add (BS, "South"); +F.add (BW, "West"); -F.add (BE, "East"); +F.add (BC, "Center"); A at - //You can also use the following statement - /* - F.add (BN, Borderlayout.north); - F.add (BS, Borderlayout.south); - F.add (BW, borderlayout.west); in F.add (BE, borderlayout.east); - f.add (BC, borderlayout.center); to */ + -F.setsize (200,200); theF.setvisible (true); * } $}
1 /*Example Name: GridLayout Application Example2 * source file name: Testgridlayout3 * Key: GridLayout layout manager's nature and usage4 */5 6 Importjava.awt.*;7 Public classTestgridlayout {8 Public Static voidMain (String args[]) {9Frame f =NewFrame ("GridLayout Example");TenButton B1 =NewButton ("B1"); OneButton B2 =NewButton ("B2"); AButton B3 =NewButton ("B3"); -Button B4 =Newbutton ("B4"); -Button B5 =NewButton ("B5"); theButton B6 =Newbutton ("B6"); -F.setlayout (NewGridLayout (3,2)); - F.add (B1); - F.add (B2); + F.add (B3); - F.add (b4); + F.add (B5); A F.add (B6); at F.pack (); -F.setvisible (true); - } -}
1 Importjava.awt.*;2 Public classtenbuttons {3 Public Static voidMain (String args[]) {4Frame f =NewFRAME ("Java frame");5F.setlayout (NewGridLayout (2,1)); 6F.setlocation (300,400);7F.setsize (300,200);8F.setbackground (NewColor (204,204,255));9Panel P1 =NewPanel (NewBorderLayout ());TenPanel P2 =NewPanel (NewBorderLayout ()); OnePanel P11 =NewPanel (NewGridLayout (2,1)); APanel P21 =NewPanel (NewGridLayout (2,2)); -P1.add (NewButton ("button"), borderlayout.west); -P1.add (NewButton ("button"), borderlayout.east); theP11.add (NewButton ("button")); -P11.add (NewButton ("button")); - P1.add (p11,borderlayout.center); -P2.add (NewButton ("button"), borderlayout.west); +P2.add (NewButton ("button"), borderlayout.east); - for(intI =1;i<=4;i++) {P21.add (NewButton ("button"));} + P2.add (p21,borderlayout.center); A F.add (p1); F.add (p2); atF.setvisible (true); - } -}
Java_ Layout Manager