/*
* 网络布局
* */
package com.swing;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
class gridlayout extends JFrame{
int size=6;
private JButton jbtn[]=new JButton[size];
public static void main(String[] args){
gridlayout glout=new gridlayout();
}
public gridlayout(){
this.setTitle("网格布局");
//设置大小
this.setSize(400,200);
//设置位置
this.setLayout(new GridLayout(3,3));
for(int i=0;i<size;i++){
jbtn[i]=new JButton(String.valueOf(i));
this.add(jbtn[i]);
}
this.setLocation(100,100);
//设置关闭时关掉进程
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
转载于:https://blog.51cto.com/6846041/1329753