I have a Java application which is used to start a Swing user interface. The interface is a class with an encapsulated JFrame instance. The problem is that the application allocates some resources and the Swing interface uses these resources, but the application closes the resource not the user interface.
How can I achieve either the main application gets a notification when the complete Swing interface is closed or that the start of the Swing interface blocks until it's closed. Closed means that the WindowAdapter.windowClosed(WindowEvent)
method of the JFrame WindowListener was already invoked.
The solution from this thread (link) seems to return when the JFrame will be invisble, does this include the WINDOW_CLOSED
event handling?
Edit: Maybe it will be a solution to implement this lifecycle interface:
public interface Lifecycle {
public void startup();
public void shutdown();
}
Now the Swing interface class has to invoke the shutdown()
method of the main application in the handler of the WindowEvent.WINDOW_CLOSED event.
Is it possible and a good pratice to do so?