网格布局的演示代码

来源:互联网 发布:js加载页面时自动执行 编辑:程序博客网 时间:2024/05/21 20:29
/***@程序名:Layout_2.java*@编程人:*******@程序功能:演示布局管理(修改Layout_1.java 体现封装思想)*@编程日期:2017-06-08*/import java.awt.*;public class Layout_2 extends Frame {Button b0 = null;Button b1 = null;Button b2 = null;Button b3 = null;Button b4 = null;Button b5 = null;Button b6 = null;Button b7 = null;Button b8 = null;Button b9 = null;Panel p1 = null;Panel p2 = null;public Layout_2(){b0 = new Button("BUTTON");b1 = new Button("BUTTON");b2 = new Button("BUTTON");b3 = new Button("BUTTON");b4 = new Button("BUTTON");b5 = new Button("BUTTON");b6 = new Button("BUTTON");b7 = new Button("BUTTON");b8 = new Button("BUTTON");b9 = new Button("BUTTON");p1 = new Panel(new GridLayout(2,1));p2 = new Panel(new GridLayout(2,2));p1.add(b0);p1.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);p2.add(b5);this.add(b6);this.add(p1);this.add(b7);this.add(b8);this.add(p2);this.add(b9);this.setLayout(new GridLayout(2,3));this.setTitle("Java Frame");this.setSize(600,300);this.setLocation(100,200);this.setVisible(true);}public static void main(String [] args){Layout_2 l = new Layout_2();}}

原创粉丝点击