Solved

How to call a method when JDialog window is closing?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is the difference between "sudo su" and "su - root" 6 106
thymeleaf natural templating vs JSP 2 68
Spring Framework HTTPSession management 1 24
map related example 6 38
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

867 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

22 Experts available now in Live!

Get 1:1 Help Now