How to start a method only after closing the frame?

So my code now looks like this:

Class2 className = new Class2(param1, param2); className = null; if (Class2 == null) { refreshState(); } 

I want the refreshState method refreshState run after the className object is className . So basically Class2 is a class that runs another frame on top of my existing frame. I want the method to run only when the new frame has been closed. How can i do this?

+4
source share
2 answers

So basically Class2 is a class that runs another frame on top of my existing frame. I want the method to run only when the new frame has been closed. How can i do this?

The best solution is to use modal dialogs like JOptionPane or modal JDialog. This will stop processing the Swing code in the main window until the dialog has been processed and is no longer visible. Then your refreshState can start immediately after closing the dialog:

pseudo code:

 main window code show modal dialog refresh state here. This will be called only after the dialog has returned. 
+3
source

I would say to add java.awt.event.WindowListener to the frame:

 class2.getFrame().addWindowsListener(new WindowAdapter() { public void windowClosed(WindowEvent we) { // The frame is closed, let dot something else refreshState(); } } 
+1
source

All Articles