setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //防止点击窗口的关闭按钮退出//退出按钮事件
btnExit.addActionListener(new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
funExit ();
}
});
//***************************************************
//名称:funExit
//功能:退出确定函数
//输入:
//输出:
//返回:
//***************************************************
private void funExit ()
{
try
{
if (JOptionPane.showConfirmDialog (this, "确定要退出系统吗?", "信息", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit (0);
}
}
catch (Exception e)
{
System.exit (0);
System.out.println (e.getMessage ());
}
}

解决方案 »

  1.   

    我使用 SWT 这个函数在那?
      

  2.   

    给shell添加.addDisposeListener() {}把 .doit = false
    试试。。
      

  3.   

    shell.addShellListener(new ShellAdapter(){
      public void shellClosed(ShellEvent e){
        e.doit = false;
      }
    });
      

  4.   

    你可以用普通的Frame,因为JFrame窗口一建立的时候它的“x”就已经有关闭的功能了!
    普通的Frame建立后“x”是需要自己添加功能的!
      

  5.   

    设置窗口关闭属性为:
      
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);然后截取关闭事件:    this.addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e)
          {    }});