psapra
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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
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
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