[java]代码库
/**
* 功能:GridLayout的简单案例
*/
package com.jiemian;
import java.awt.*;
import javax.swing.*;
public class Text3 extends JFrame{
int size=9;
JButton jbs[]=new JButton[size];
public static void main(String[] args) {
Text3 text3=new Text3();
}
public Text3(){
//创建组件
for(int i=0;i<size;i++){
jbs[i]=new JButton(String.valueOf(i));
}
//设置布局管理器
this.setLayout(new GridLayout(3, 3,5,5));
//添加组件
for (int i = 0; i < size; i++) {
this.add(jbs[i]);
}
//设置窗体属性
this.setSize(300,200);
this.setLocation(200, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}