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




//窗口事件
		this.addWindowListener(new WindowListener()
		{
			public void windowActivated(WindowEvent e){}
			public void windowClosed(WindowEvent e){}
			public void windowClosing(WindowEvent e){}//sysTray.remove(trayIco);}
			public void windowDeactivated(WindowEvent e){}//setVisible(false);requestFocus();}//显示最前
			public void windowDeiconified(WindowEvent e){}
			public void windowIconified(WindowEvent e){}
			public void windowOpened(WindowEvent e){}
		});

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