Solved

How to call a method when JDialog window is closing?

Posted on 2001-07-18
2
244 Views
Last Modified: 2008-03-10

Hi

    i want to call a method when the JDialog is closing?.
i have tried with
protected void processWindowEvent(WindowEvent evt).
but it is not entering into that method while closing the window.
please give me a sample code

thanks
0
Comment
Question by:mmsreddy
2 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 100 total points
ID: 6293478
addWindowListener(new AppCloser());

/**
* To shutdown when run as an application.  This is a
* fairly lame implementation.   A more self-respecting
* implementation would at least check to see if a save
* was needed.
*/
    protected static final class AppCloser extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
     // your actions after closing the window    
        //System.exit(0);
   }
}

It's snip of code for application. But it will work for your JDialog as well.

Best regards,
Valeri
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 6293872
There is another way if your JDialog is being called from some other component...oh, lets say...a JFrame?  

The call to the JDialog is triggered somewhere in that code, or any other controlling class that you might have.  They you only have to make that call directly after the control returns from the JDialog.  There are many different possiblities.  You can set a boolean variable to be changed if the proper actions were taken, if not correctly performed then trigger the new method--ie a JOptionPane message.  

I usually get rid of the JDialog with the 'dispose();' method, returning control to the calling class.  

But since you are wanting to close the program entirely with a system exit, then this is just food for thought.

Tom
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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