首页
学习
活动
专区
圈层
工具
发布

Java开发GUI之绝对布局 原

Java开发GUI之绝对布局

    前面多篇博客介绍了Java的awt包中的布局管理类,当然也可以不使用任何布局管理类,开发者可以直接设置组件的坐标和尺寸,示例代码如下:

代码语言:javascript
复制
	static void AbsoluteLayoutTest(){
		Frame frame = new Frame("Grid");
		//设置不使用任何布局管理类
		Panel pannel = new Panel(null);
		Button button1 = new Button("Button1");
		pannel.add(button1);
		button1.reshape(10, 10, 60, 20);
		Button button2 = new Button("Button2");
		pannel.add(button2);
		button2.reshape(80, 40, 60, 20);
		Button button3 = new Button("Button3");
		pannel.add(button3);
		button3.reshape(10, 70, 60, 20);
	
		frame.add(pannel);
		frame.pack();
		frame.show();
	}

组件的reshape方法用于重设组件的位置和尺寸,其前两个参数确定x,y坐标,后两个参数确定宽度与高度,效果如下图:

举报
领券