Solved

How to call a method when JDialog window is closing?

Posted on 2001-07-18
2
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

690 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