编写Java程序,使用JFrame创建一个窗体

返回本章节

返回作业目录


需求说明:

使用JFrame创建一个窗体

实现思路:

使用JFrame创建窗体的思路

定义一个窗体对象f,窗体名称为“一个简单窗口”

设置窗体左上角与显示屏左上角的坐标

//离显示屏上边缘300像素,离显示屏左边缘300像素

f.setLocation(300,300);

设置窗体的大小

设置窗体可见

用户单击窗口的关闭按钮时程序执行的操作

f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);

实现代码:

import javax.swing.JFrame;

public class Test {
	public static void main(String[] args) {
		JFrame f = new JFrame();
		f.setTitle("一个简单窗口");
		f.setLocation(300,300);
		f.setSize(600, 400);
		f.setVisible(true);
		f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_44893902/article/details/106793133