Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

asked on

Closing / Terminating a dialog window

My code is calling and opening a dialog window.  I am wanting to call a method when the user either hits the cancel button or terminates the window using the x button on the top tight corner.

I am not sure if I need to write a method or there is already a method that gets called.  
How would I go about doing this?

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

When the use hits cancel button you can just
call

this.dispose()

if you are handilng events inside your daailog
To close with the x at corner

you need to implement WindowListener (add implemnets WindowListener in the declaraion of the calss)

and add these methods to your code in your dilaog:
public void windowClosing(WindowEvent evt) {
this.dispose();
}

public void windowOpened(WindowEvent evt){}
public void windowIconified(WindowEvent evt){}
public void windowDeiconified(WindowEvent evt){}
public void windowActivated(WindowEvent evt){}
public void windowDeactivated(WindowEvent evt){}
public void windowClosed(WindowEvent evt){}

Open in new window

Avatar of jkteater

ASKER

Once again thanks for much for the quick response from both of you.  I was able to take CEHJ suggestion and get that working.  for_yan I love the example, but already completed.
:)