Borderlayout a border layout arranges and resizes containers components to fit in five regions: north, south, east, west and center Each region may contain no more than one component North West Center Fast South 16
16 BorderLayout • A border layout arranges and resizes container’s components to fit in five regions: north, south, east, west, and center. • Each region may contain no more than one component
Borderlayout example Import java. awt public class button Dir( public static void main(String argsi Frame f= new Frame "BorderLayout") f. setLayout(new BorderLayouto); f. add("North", new Button("North" )); f. add("South", new Button(" South")) f. add("East", new Button(East")); f. add("West", new Button("West") BorderLayout North f. add("Center", new Button("Center")) f setSize(200, 200) f set Visible(true); West Center East South
17 BorderLayout Example import java.awt.*; public class buttonDir{ public static void main(String args[]){ Frame f = new Frame("BorderLayout"); f.setLayout(new BorderLayout()); f.add("North", new Button("North")); f.add("South", new Button("South")); f.add("East", new Button("East")); f.add("West", new Button("West")); f.add("Center", new Button("Center")); f.setSize(200,200); f.setVisible(true); } }
GridLayout out a container's components in a rectangular gd The gridlayout class is a layout manager that lay
18 GridLayout • The GridLayout class is a layout manager that lays out a container's components in a rectangular grid
GridLayout Import java. awt public class Button grid public static void main(String args Frame f=new Frame( GridLayout") f. setLayout(new Grid Layout(3, 2)); //3 rows 2 columns f. add(new Button(" 1")) f. add(new Button( 2 )) f. add(new Button( 3 )) f. add (new Button(4)) GridLayout 口 f. add(new Button("5")) f. add(new Button("6")) f setSize(200, 200) 3 f set visible(true) 6 19
19 GridLayout import java.awt.*; public class ButtonGrid { public static void main(String args[]) { Frame f = new Frame("GridLayout"); f.setLayout(new GridLayout(3,2)); //3 rows & 2 columns f.add(new Button("1")); f.add(new Button("2")); f.add(new Button("3")); f.add(new Button("4")); f.add(new Button("5")); f.add(new Button("6")); f.setSize(200,200); f.setVisible(true); } }
CAble A J Label can display both text and images Example JLabelDemo. java in Unit 3.2.1 段 abelDemo Hello Hello 20
20 JLable • A JLabel can display both text and images • Example: JLabelDemo.java in Unit 3.2.1