I have an application which on exit should close all windows and write some configuration files.
Without the things I did below, the following was never triggered and so the closeEXES which writes all the configs out was never run.
mainframe.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(WindowEvent winEvt) {
closeEXES();
}
});
I used the following to catch the Cmd-Q on Mac OS:
import com.apple.eawt.QuitStrategy;
import com.apple.eawt.Application;
And in main:
if (System.getProperty("os.name").equals("Mac OS X")) {
Application.getApplication().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
The version before that I did:
public class MacQuitAdapter extends ApplicationAdapter {
@Override
public void handleQuit(ApplicationEvent e) {
System.out.println("Using deprecated AplicationAdapter for handling Quit.");
}
}
How would I accomplish the same thing with JDK 8? The "same thing" is to make sure that when Command-Q is hit, the closing of the windows will be passed to AWT so that the windowClosing method will do what I want.
Alternatively, is there some other listener I need to sense the Command-Q? I'll keep looking but thought it was worth asking here.
Thanks.