如果你所说的X按钮 是说右上角的那个的话 那么就这样吧 jDialog.addWindowListener( new WindowAdapter(){ public void windowClosing( WindowEvent we ){ // do thing......... } }
也可以继承 JDialog 类 增加处理函数 public void close() { // operation before close processWindowEvent( new WindowEvent( this, WindowEvent.WINDOW_CLOSING ); // operation after close }
是说右上角的那个的话
那么就这样吧
jDialog.addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent we ){
// do thing.........
}
}
增加处理函数
public void close()
{
// operation before close
processWindowEvent( new WindowEvent( this, WindowEvent.WINDOW_CLOSING );
// operation after close
}
可是当我点击右上角的X按钮时
他没有进入windowClosing的这个函数啊
* 重载父类方法,退出处理
* @param e 窗口事件
*/
public void processWindowEvent(WindowEvent e){
if(e.getID() == WindowEvent.WINDOW_CLOSING ){
funcExit();
return;
}
super.processWindowEvent(e);
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
this.dispose() ;//关闭窗体的语句,也可以在前面加上自己的东西。
}
}