JDialog close event ( ALT+F4 or clicking 'X' )

I have an applet that displays a modal JDialog. I need to capture the following two events :

1. The user presses ALT+F4 to close the dialog
-- OR --
2. The user clicks on "x" on the top right corner to close the dialog.

In either case, I need to do processing before the dialog is actually closed.

Please paste a code sample if you have any ideas.

Thanks.


psapraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

expertmbCommented:
hi,

   this will help u

 protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
   // write what u wanthere
   // my code
      fileExit_actionPerformed(null);
    }
  }

good luck

 mb...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sgomsCommented:
Try this,

class myDialog extends JDialog{
     myDialog(){
     ////
     addWindowListener(new WindowAdapter(){
       //capture the window closing event i.e clicking 'X'
       public void windowClosing(WindowEvent evt){
          ///do any actions that u wish to
          dispose();//dispose the JDialog
       }
     });
....
}

The steps are,
1. add a windowlistener to ur class. so that u can capture all the window events.
2. have an anonymous class declatarion for using windowadapter class.
3. capture teh windowClosing event.

-sgoms
0
psapraAuthor Commented:
Thanks for your suggestions. Even though both of them work fine, I have gone with the solution proposed by sgoms only because of the similarity to the code that I have for handling other events.

sgoms, I don't have a way of splitting any points, but I really really do appreciate your helping out.

Thanks a lot for your help.

0
sgomsCommented:
well..glad that it worked for u.
for future reference:

if u wish to give points to another expert's comment then u CAN reject an answer & 'accept comment as answer' for the other comment.

else post an empty question to give points if u wish to split the points.

-sgoms
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.