java JFrame关闭事件 我重写了 windowClosing 事件在点退出按钮的时候 我希望直接触发windowClosing事件也就是JFrame 右上角的关闭按钮setVisible 和 dispose() 失败`请大家想想`办法`~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置默认关闭事件对JFrame,JDialog,JInternalFrame有效setDefaultCloseOperation(EXIT_ON_CLOSE);可用参数在javax.swing.WindowConstants内(JFrame,JDialog,JInternalFrame都实现了)DO_NOTHING_ON_CLOSE = 0;HIDE_ON_CLOSE = 1;DISPOSE_ON_CLOSE = 2;EXIT_ON_CLOSE = 3;2、使用內部類實現窗體關閉事件的捕獲protected static class CloseHandlerextends WindowAdapter{public void windowClosing(final WindowEvent event){//要做的動作 System.exit(0);}} this.setDefaultCloseOperation(EXIT_ON_CLOSE)这是关闭按钮的事件,可以添加它来实现 this.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent we){ this.setVisible(flase); System.exit(0); } } );当然,既然楼主用了javax.swing了,用setDefaultCloseOperation(EXIT_ON_CLOSE); 就可以! 大家辛苦了`~~我的意思没有表达明确 ̄现在有主界面 jf 和 子界面 jf1 都是 JFrame子界面显示的时候 主界面不可编辑 就是仿的 JDialog模式jf1.addWindowListener(new JFrameEnable());jf1.setVisible(true);JFrame jf= (JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, ButtonMenu.this);jf.setEnabled(false);//界面切换class JFrameEnable extends WindowAdapter{ public void windowClosing(WindowEvent e) { //主界面显示 SwingUtilities.getAncestorOfClass(JFrame.class, ButtonMenu.this).setEnabled(true);} }在jf1里有个退出按钮如果直接 setVisible 和 dispose() 就没有触发 windowClosing 事件 也就无法将主界面显示 java编程 求一个负整数的二进制数 几个小问题 能给我说一下编程语言吗 请问JRadioButton要使它由选中到不被选种的语句是什么?? 请问java查询SQLServer数据库的问题 请各位帮我改改程序吧,我编写的程序有问题 drill down at INT type. struct是什么东西,是种工具!类库,还是其它。 输入输出方面的问题 Java Bean中的Bean译成中文到底是什么意思???不会是“豆子”吧?谢谢高人指点 急,在线等一个Java下雨小动画 如何更好的学习!!!!!
setDefaultCloseOperation(EXIT_ON_CLOSE);
可用参数在javax.swing.WindowConstants内(JFrame,JDialog,JInternalFrame都实现了)
DO_NOTHING_ON_CLOSE = 0;HIDE_ON_CLOSE = 1;DISPOSE_ON_CLOSE = 2;EXIT_ON_CLOSE = 3;
2、使用內部類實現窗體關閉事件的捕獲protected static class CloseHandlerextends WindowAdapter{public void windowClosing(final WindowEvent event){//要做的動作 System.exit(0);}}
this.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent we){
this.setVisible(flase);
System.exit(0);
}
}
);
当然,既然楼主用了javax.swing了,用setDefaultCloseOperation(EXIT_ON_CLOSE); 就可以!
我的意思没有表达明确 ̄现在有主界面 jf 和 子界面 jf1 都是 JFrame
子界面显示的时候 主界面不可编辑 就是仿的 JDialog模式jf1.addWindowListener(new JFrameEnable());
jf1.setVisible(true);
JFrame jf= (JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, ButtonMenu.this);
jf.setEnabled(false);
//界面切换
class JFrameEnable extends WindowAdapter{
public void windowClosing(WindowEvent e) {
//主界面显示
SwingUtilities.getAncestorOfClass(JFrame.class, ButtonMenu.this).setEnabled(true);
}
}在jf1里有个退出按钮
如果直接 setVisible 和 dispose()
就没有触发 windowClosing 事件
也就无法将主界面显示