Question: In a Java application on a Mac, you can click the top bar and select Quit to exit the program. How can I add a listener to my JFrame to listen to this?

I did a search on this and found ApplicationListener, however Eclipse puts a "cross out" in this and seems to think its deprecated or something.

Specifically, I found to use com.apple.eawt.ApplicationListener, but how do I do this? Do I need to download this com.apple.eawt package? I can't seem to find it.

Answer: 
You need to register an ApplicationListener:

There is a sample application available from Apple:

<http://developer.apple.com/library/mac/#samplecode/OSXAdapter/Introduction/Intro.html>
In Java 9, you should use the cross-platform Desktop API, as the Mac EAWT APIs have been deprecated:

```
if (Desktop.isDesktopSupported()) {
    Desktop desktop = Desktop.getDesktop();
    desktop.setQuitHandler(new QuitHandler()
    {
        @Override
        public void handleQuitRequestWith(QuitEvent evt, QuitResponse res)
        {
            // TODO: Handle the quit request
            // res.cancelQuit();  // Cancel the quit request
        }
    });
}

```