[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3500
  • Last Modified:

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.


0
psapra
Asked:
psapra
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now