Solved

How to call a method when JDialog window is closing?

Posted on 2001-07-18
2
238 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

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

759 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

17 Experts available now in Live!

Get 1:1 Help Now