禁用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);
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章