流式布局
FlowLayout
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
东西南北中
BorderLayout
frame.add(botten1,BorderLayout.EAST)
表格
GridLayout
frame.setLayout(new GridLayout(2,4));
代码
Frame frame = new Frame();
Button button1= new Button(“East”);
Button button2= new Button(“West”);
Button button3= new Button(“South”);
Button button4= new Button(“North”);
Button button5= new Button(“Center”);
Button button6= new Button(“Center”);
frame.setVisible(true);
frame.setBounds(100,100,500,300);
frame.setResizable(false);
frame.setBackground(Color.red);
frame.setLayout(new GridLayout(2,3));
frame.setLayout(new FlowLayout(FlowLayout.LEFT));
// frame.add(button1,BorderLayout.EAST);
// frame.add(button2,BorderLayout.WEST);
// frame.add(button3,BorderLayout.SOUTH);
// frame.add(button4,BorderLayout.NORTH);
// frame.add(button5,BorderLayout.CENTER);
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.add(button6);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}