import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test extends JFrame{//把需要的元件全部在這裡定義
JButton an1,an2,an3,an4,an5;
public static void main(String[] args){
Test lx=new Test();
}
public Test(){
an1=new JButton("東方");
an2=new JButton("西方");
an3=new JButton("南方");
an4=new JButton("北方");
an5=new JButton("中部");
this.add(an1,BorderLayout.EAST);//括號中的引數都是固定的,順序不能變
this.add(an2,BorderLayout.WEST);//前面是物件,後面是佈局管理器
this.add(an3,BorderLayout.SOUTH);
this.add(an4,BorderLayout.NORTH);
this.add(an5,BorderLayout.CENTER);
//如果不是五個按鈕全部新增,則會以擴充中部為主進行填充,但中部不會被其它四個填充
this.setTitle("邊界佈局BorderLayout");
this.setSize(380,320);
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}