我的笔记 网格布局 GridLayout

来源:互联网 发布:dht网络 编辑:程序博客网 时间:2024/06/06 10:39
import java.awt.*;
import javax.swing.*;
public class wangge extends JFrame {
    JButton[] an={null,null,null,null,null,null,null,null,null};//添加一个JButton 按钮属性。
    public static void main(String[] args)
    {
        wangge A=new wangge();
    }
    public wangge()
    {
        an[0]=new JButton("话梅");
        an[1]=new JButton("果盘");
        an[2]=new JButton("薯片");
        an[3]=new JButton("披萨");
        an[4]=new JButton("饼干");
        an[5]=new JButton("巧克力");
        an[6]=new JButton("腰果");
        an[7]=new JButton("杏仁");
        an[8]=new JButton("开心果");
        this.setLayout(new GridLayout(3,3,2,2));// 括号里的数字 代表的是 行,列 ,行空 ,列空
        for(int i=0;i<an.length;i++)
        {
            this.add(an[i]);
        }
        this.setTitle("网格布局GridLayout");
        this.setSize(380,200);
        this.setLocation(200,200);
        this.setResizable(false); //Resizable 可变的尺寸 
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);// Visible 可视的
    }
}
0 0
原创粉丝点击