public static void main(String[] args) {
// 定义窗口
Frame frame = new Frame();
// 设置窗口大小
frame.setSize(400, 400);
// 设置窗口坐标
frame.setLocation(200, 200);
// 设置窗口颜色
frame.setBackground(Color.BLACK);
// 设置窗口显示
frame.setVisible(true);
}
窗口大小和窗口坐标一起设置
public static void main(String[] args) {
// 定义窗口
Frame frame = new Frame();
// 设置窗口大小,坐标
frame.setBounds(200, 200, 400, 400);
// 设置窗口颜色
frame.setBackground(Color.BLACK);
// 设置窗口显示
frame.setVisible(true);
}
? 点击窗口的X无法关闭,得自定义窗口监听按钮,对窗口进行关闭
public static void main(String[] args) {
// 定义窗口
Frame frame = new Frame();
// 设置窗口大小,坐标
frame.setBounds(200, 200, 400, 400);
// 设置窗口颜色
frame.setBackground(Color.BLACK);
// 关闭窗口
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// 终止程序
System.exit(0);
}
});
// 设置窗口显示
frame.setVisible(true);
}
原文:https://www.cnblogs.com/longma-ling/p/14652445.html