布局管理器:
BorderLayout 边界布局管理器
public class AwtTest extends Frame{
//创建框架
public static void main(String[] args) {
Frame frame = new Frame();
frame.setLayout(new BorderLayout(5,7));
frame.add(new Button("东"),new BorderLayout().EAST);
frame.add(new Button("南"),new BorderLayout().SOUTH);
frame.add(new Button("西"),new BorderLayout().WEST);
frame.add(new Button("西"),new BorderLayout().NORTH);
frame.add(new Button("中"),new BorderLayout().CENTER);
frame.setBounds(100,100,500,500);
frame.setVisible(true);
}
}
CardLayout:卡式布局管理器
public class AwtTest extends Frame{
//创建框架
public static void main(String[] args) {
Frame frame = new Frame();
CardLayout c =new CardLayout(5,7);
frame.setLayout(c);
frame.add(new Button("西"),"1");
frame.add(new Button("北"),"2");
frame.add(new Button("中"),"3");
c.show(frame,"1");
frame.setBounds(100,100,500,500);
frame.setVisible(true);
}
}
FlowLayout:流式布局管理器
public class AwtTest extends Frame{
//创建框架
public static void main(String[] args) {
Frame frame = new Frame();
frame.setLayout(new FlowLayout(FlowLayout.LEFT,5,7));
frame.add(new Button("东"));
frame.add(new Button("南"));
frame.add(new Button("西"));
frame.add(new Button("北"));
frame.add(new Button("中"));
TextField t = new TextField("121231212123",50);
frame.add(t);
frame.setBounds(100,100,500,500);
frame.setVisible(true);
}
}
GridLayout:网格布局管理器
public class AwtTest extends Frame{
//创建框架
public static void main(String[] args) {
Frame frame = new Frame();
GridLayout c =new GridLayout(5,5,5,5);
frame.setLayout(c);
frame.setBounds(100,100,500,500);
frame.setVisible(true);
for(int i =0;i<25;i++){
frame.add(new Button(new Integer(i).toString()));
}
}
}
GridBagLayout:网格包装布局管理器