禁用swing窗体右上角关闭按钮

其实还可以通过评比关闭按钮的事件来达到该效果

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);
}
}

你可能感兴趣的:(java,swing)