static int
static int
static int
static int
setDefaultCloseOperation()是用来设定窗口被关闭时候(比如点击了右上角的"x")的行为的。
DISPOSE_ON_CLOSE在窗口被关闭的时候会dispose这个窗口。
EXIT_ON_CLOSE在窗口被关闭的时候会退出JVM。
如果你的程序没有其他线程在运行的话,当所有的窗口都被dispose了之后,JVM也会退出。
package xiya;
import javax.swing.*;
import static javax.swing.JFrame.*;
public class Example10_1 {
public static void main(String[] args) {
JFrame windows1 = new JFrame("窗口一");
JFrame windows2 = new JFrame("窗口二");
windows1.setBounds(200,100,360,260);
windows2.setBounds(560,100,360,260);
windows1.setVisible(true);
windows1.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
windows2.setVisible(true);
windows2.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}