/**
* 网格布局
*
* @time 3:22:44 PM
* @author retacn yue
* @Email
[email protected]
*/
@SuppressWarnings("unused")
public class Test_GridLayoutDemo extends Frame {
private static final long serialVersionUID = 1L;
Button b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bm, bd, be, bp;
Panel panel;
/**
* 构造器
*/
public Test_GridLayoutDemo() {
super("网格布局管理器");
panel = new Panel();
panel.setBackground(Color.orange);
/**
* 网格布局
*/
panel.setLayout(new GridLayout(4, 4, 3, 3));
b7 = new Button("A");
panel.add(b7);
b8 = new Button("B");
panel.add(b8);
b9 = new Button("C");
panel.add(b9);
bd = new Button("D");
panel.add(bd);
b4 = new Button("E");
panel.add(b4);
b5 = new Button("F");
panel.add(b5);
b6 = new Button("G");
panel.add(b6);
bp = new Button("H");
panel.add(bp);
b1 = new Button("I");
panel.add(b1);
b2 = new Button("J");
panel.add(b2);
b3 = new Button("K");
panel.add(b3);
bm = new Button("L");
panel.add(bm);
b0 = new Button("M");
panel.add(b0);
ba = new Button("N");
panel.add(ba);
be = new Button("O");
panel.add(be);
this.add("Center", panel);
this.setSize(200, 200);
this.setVisible(true);
addWindowListener(new koWindowListener());
}
public static void main(String[] args) {
Test_GridLayoutDemo gridLayoutDemo = new Test_GridLayoutDemo();
}
/**
* 自定义关闭窗口
*/
class koWindowListener extends WindowAdapter {
@Override
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
}
}
}