其实还可以通过评比关闭按钮的事件来达到该效果
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class MyFrame extends JFrame {
MyFrame() {
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
} else {
super.processWindowEvent(e);
}
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setSize(new Dimension(500, 500));
frame.setVisible(true);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class MyFrame extends JFrame {
MyFrame() {
}
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
} else {
super.processWindowEvent(e);
}
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setSize(new Dimension(500, 500));
frame.setVisible(true);
}
}