Friday, August 9, 2013

Java Close Window With Confirmation Dialog

   public void close(){
              int p = JOptionPane.showConfirmDialog(null, "Do you really want to Exit","Exit",JOptionPane.YES_NO_OPTION);
                if(p == 0){
                try{
                        WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
                        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
                }catch(Exception e){
                       
                   JOptionPane.showMessageDialog(this, e, "Invalid", JOptionPane.ERROR_MESSAGE);
        }
           
       }
    }

No comments:

Post a Comment