Link to home
Start Free TrialLog in
Avatar of Drop_of_Rain
Drop_of_Rain

asked on

adding JOptionPane to closing the window

How would I transfer this JoptionPane to my standard window closing? There won't be a button just the x at the top of the window.

public windowVerify(){  
                                                  JButton close = new JButton("Close");
                                                  close.addMouseListener(new MouseAdapter(){
                                                       public void mouseClicked(MouseEvent e){
                                                            JOptionPane dlg = new JOptionPane();
                        if(JOptionPane.OK_OPTION==dlg.showConfirmDialog(null,"Want to exit ?","Message",JOptionPane.YES_NO_OPTION ))
                                                                 System.exit(0);
                                                       }
                                                  });
getContentPane ().setLayout(new FlowLayout());
getContentPane ().add(close);
                                             }

 public void windowClosing(WindowEvent e)
            { // Opens windowClosing method
                System.exit(0);
            } // Closes windowClosing method
        }); // Closes addWindowListener method
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Drop_of_Rain
Drop_of_Rain

ASKER

I though that was it I should of tried it first. Thanks as always