布局方式(边界布局)

来源:互联网 发布:人工智能是什么意思 编辑:程序博客网 时间:2024/06/05 16:24
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class TestBorderLayout extends JFrame {

    JButton jb1=null;
    JButton jb2=null;
    JButton jb3=null;
    JButton jb4=null;
    JButton jb5=null;
    public TestBorderLayout(){
        this.setBounds(100, 100, 300, 600);
        
        this.setTitle("布局学习");
        this.setVisible(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        inti() ;
        addc();
    }
    private void addc() {
        //设置容器的布局方式(边界布局)
        this.setLayout(new BorderLayout());
        //添加组件
        this.add(jb1,BorderLayout.EAST);
        this.add(jb2,BorderLayout.SOUTH);
        this.add(jb3,BorderLayout.WEST);
        this.add(jb4,BorderLayout.NORTH);
        this.add(jb5,BorderLayout.CENTER);
    
        
        
    
    }
    private void inti() {

        jb1=new JButton("东");
        jb2=new JButton("南");
        jb3=new JButton("西");
        jb4=new JButton("北");
        jb5=new JButton("中");
    
        
    }

}


--------------------------------------------------------------------



public class Test1 {

    public static void main(String[] args) {
        new TestBorderLayout();

    }

}



原创粉丝点击