gridbaglayoutstep1.java

来自「JAVA SE6 全方位学习 朱仲杰 编著 机械工业出版社出版」· Java 代码 · 共 37 行

JAVA
37
字号
import java.awt.*;public class GridBagLayoutStep1{	public static void main(String argv[])	{		Frame f = new Frame("GridBagLayout Step 1");		f.setLayout(new GridBagLayout());		Button b[] = new Button[4];		int att[][] = { {0, 0, 1, 1}, 						{1, 0, 1, 1}, 						{2, 0, 1, 1},						{0, 1, 3, 1} };		for (int i=0; i<b.length; i++)		{			b[i] = new Button("Button "+(i+1));	                add(f, b[i], att[i]);		}		f.pack();		f.setVisible(true);	}	private static void add(Container con, Component com, int att[])	{		GridBagConstraints cons = new GridBagConstraints();		cons.gridx = att[0];		cons.gridy = att[1];		cons.gridwidth = att[2];		cons.gridheight = att[3];		con.add(com, cons);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?