swing之borderlayout

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

//1.繼承 JFrame類
//2.在最上方定義組件
//3.在構造方法中建立組件
//四、在構造方法中添加組件
//5.設置窗體屬性
//6.顯示窗體
//7.在主函數中建立對象
public class borderlayout1 extends JFrame{
    JButton jb1,jb2,jb3,jb4,jb5;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        borderlayout1 b2=new borderlayout1();
    }

    
    public  borderlayout1()
         {
        jb1=new JButton("");
        jb2=new JButton("西");
        jb3=new JButton("");
        jb4=new JButton("");
        jb5=new JButton("");
        
        this.add(jb1,BorderLayout.EAST);//第一個參數是對象,第二個是佈局管理器
        this.add(jb2,BorderLayout.WEST);
        this.add(jb3,BorderLayout.SOUTH);
        this.add(jb4,BorderLayout.NORTH);
        this.add(jb5,BorderLayout.CENTER);
        this.setTitle("邊界佈局borderlayout");
        this.setSize(380,320);
        this.setLocation(200, 200);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
         }
}
相關文章
相關標籤/搜索