各位前辈请教一个问题,我现在想关闭自己的JFrame的时候弹出一个对话框并且可以选择确定和取消。因该怎么做那。这里我没有充足的资料可否指点一下那。JDialog 或者说怎么用那?
Thank`

解决方案 »

  1.   

    先设置JFrame:setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    再用JFrame的Closing事件:public void windowClosing(WindowEvent e)
    {
    if(JOptionPane.showConfirmDialog(this,"Are you sure to exit?","Exit Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION)
           {
               System.exit(0);
           }
    }
      

  2.   

    guiclose.addWindowListener(new WindowAdapter()
                             {
                     public void windowClosing(WindowEvent e)
                       {
                        if (JOptionPane.showConfirmDialog(null, "你确定退出程序嘛?",
                        "Exit Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE) ==
                            JOptionPane.YES_OPTION) {
                          logger.debug("End Ddebug....");
                          logger.info("leaving the application");
                         // NDC.pop();
                         System.out.println("This is RootLogger...ing ."+logger.getRootLogger());
                          System.exit(0);                    }
                      }
                             });谢谢楼上:这样可以拉!
      

  3.   

    除了System.exit()还有其他方法没呀?