1 packageLayout;2 Importjava.awt.*;3 Importjavax.swing.*;4 public classMyborderlayoutextendsjframe{5 PrivateJButton B1 =NewJButton ("east");6 PrivateJButton B2 =NewJButton ("south");7 PrivateJButton B3 =NewJButton ("west");8 PrivateJButton B4 =NewJButton ("north");9 PrivateJButton B5 =NewJButton ("medium");Ten publicmyborderlayout () { one aSettitle ("user interface"); -SetSize (500, 500); -setlocation (100, 100); the Add (b1,borderlayout.east); - Add (b2,borderlayout.south); - Add (b3,borderlayout.west); - Add (b4,borderlayout.north); + Add (b5,borderlayout.center); - + setdefaultcloseoperation (jframe.exit_on_close); aSetVisible (true); at } - - - public Static voidmain (string[] Args) { -Myborderlayout L =Newmyborderlayout (); - in } - to}
1 packageLayout;2 Importjava.awt.*;3 Importjava.util.HashMap;4 Importjava.util.Map;5 6 Importjavax.swing.*;7 public classMyflowlayoutextendsjframe{8 Privatemap<string,jbutton> map =NewHashMap ();9 PrivateJButton B =NewJButton ();Ten publicmyflowlayout () { oneMap.put ("B1",NewJButton ("B1")); aMap.put ("B2",NewJButton ("B2")); -Map.put ("B3",NewJButton ("B3")); -Map.put ("B4",NewJButton ("B4")); theMap.put ("B5",NewJButton ("B5")); - this. setlayout (NewFlowLayout ()); - //this.setlayout (new flowlayout (flowlayout.left)); - //this.setlayout (new flowlayout (flowlayout.right)); + this. Add (map.get ("B1")); - this. Add (map.get ("B2")); + this. Add (map.get ("B3")); a this. Add (map.get ("B4")); at this. Add (map.get ("B5")); - this. Settitle ("user interface"); - this. setSize (500, 400); - this. setlocation (400, 500); - this. setvisible (true); - } in - to public Static voidmain (string[] Args) { + -Myflowlayout L =Newmyflowlayout (); the } * $}
1 packageLayout;2 Importjava.awt.*;3 Importjava.util.HashMap;4 Importjava.util.Map;5 Importjavax.swing.*;6 public classMygridlayoutextendsJFrame {7 Privatemap<string,jbutton> map =NewHashMap ();8 publicmygridlayout () {9 TenMap.put ("B1",NewJButton ("B1")); oneMap.put ("B2",NewJButton ("B2")); aMap.put ("B3",NewJButton ("B3")); -Map.put ("B4",NewJButton ("B4")); -Map.put ("B5",NewJButton ("B5")); theMap.put ("B6",NewJButton ("B6")); -Map.put ("B7",NewJButton ("B7")); -Map.put ("B8",NewJButton ("B8")); -Map.put ("B9",NewJButton ("B9")); + this. Add (map.get ("B1")); - this. Add (map.get ("B2")); + this. Add (map.get ("B3")); a this. Add (map.get ("B4")); at this. Add (map.get ("B5")); - this. Add (map.get ("B6")); - this. Add (map.get ("B7")); - this. Add (map.get ("B8")); - this. Add (map.get ("B9")); - in this. Settitle ("user interface"); - this. setSize (500, 600); to this. setlocation (500, 500); + this. setvisible (true); - this. setlayout (NewGridLayout (3,3,15,15)); the * } $ public Static voidmain (string[] Args) {Panax NotoginsengMygridlayout L =Newmygridlayout (); - the } + a}
Java Graphical interface layout Manager