package second;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class BorderLayoutDemo {
private Frame fb;
private Button b1,b2,b3,b4,b5;//声明5个button
//构造函数,实例化button 1 - 5
BorderLayoutDemo(){
b1 = new Button("1");//上北
b2 = new Button("2");//下南
b3 = new Button("3");//左西
b4 = new Button("4");//右东
b5 = new Button("5");//中
}
public static void main(String[] args){
BorderLayoutDemo ly = new BorderLayoutDemo();
ly.show();//显示
}
public void show(){
fb = new Frame("BorderLayout顺序布局");//框架
fb.setSize(500,200);//设置大小
fb.setLayout(new BorderLayout());
fb.add(BorderLayout.NORTH,b1);//将按钮添加到框架中
fb.add(BorderLayout.SOUTH,b2);
fb.add(BorderLayout.WEST,b3);
fb.add(BorderLayout.EAST,b4);
fb.add(BorderLayout.CENTER,b5);
fb.addWindowListener(new WindowAdapter(){//监视关闭按钮,不然TMD根本关不掉
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
fb.setVisible(true);//最后显示出来
}
}
效果如下: