Assuming that Runtime.getRuntime().addShutdownHook(new Thread() has been set up correctly, how can the ShutdownHook thread be invoked when a Java application window (JFrame) is closed (in this case the only window) and the dispose window default close operation is DISPOSE_ON_CLOSE or EXIT_ON_CLOSE?
Note that for a quit command handled with a System.exit(0) which is then fed through the ShutdownHook thread, the application terminates correctly as all the associated threads are terminated before the Java application exits. So I want to accomplish the same thing by making the closing of the JFrame window go through the ShutdownHook thread clean up.
This works according to your spec. If I close the frame by clicking the
Xbutton, the shutdown hook is invoked.