i 绝望

依然

Miss Lang

java代码用户界面网格布局GridLayout.划分为格子区域

总结:网格布局。很简单,首先要new一个   this.setlayout(new GriedLayout(3,5));里面是行数和列数

package clientFrame;

//网格布局练习
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JButton;

public class Wang extends JFrame {
	JButton bt1, bt2, bt3, bt4, bt5, bt6;

	public Wang() {
		bt1 = new JButton("饼干");
		bt2 = new JButton("瓜子");
		bt3 = new JButton("蛋糕");
		bt4 = new JButton("话梅");
		bt5 = new JButton("开心果");
		bt6 = new JButton("年糕");
		this.setLayout(new GridLayout(3, 2));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setSize(400, 400);
		this.add(bt1);
		this.add(bt2);
		this.add(bt3);
		this.add(bt4);
		this.add(bt5);
		this.add(bt6);

		// 先练习边界布局。我做错了
	}

	public static void main(String[] args) {
		Wang a = new Wang();
	}
}

  

 

posted on 2013-11-30 22:44  juewang  阅读(2493)  评论(0编辑  收藏  举报

绝望依然

Miss Lang