Solved

adding JOptionPane to closing the window

Posted on 2004-08-06
3
325 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:Drop_of_Rain
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 11741700
public void windowClosing(WindowEvent e)
            { // Opens windowClosing method
 if(JOptionPane.OK_OPTION==JOptionPane.showConfirmDialog(null,"Want to exit ?","Message",JOptionPane.YES_NO_OPTION ))
                                                                 System.exit(0);
            } // Closes windowClosing method
        }); // Closes addWindowListener method
0
 

Author Comment

by:Drop_of_Rain
ID: 11741709
I though that was it I should of tried it first. Thanks as always
0
 
LVL 92

Expert Comment

by:objects
ID: 11741713
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now