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: 
The answer is to use the newer version QuitHandler, available from Apple Java extension
For Java 7, QuitHandler is the interface to be implemented. 

```
import com.apple.eawt.QuitHandler;
import com.apple.eawt.Application;

```

somewhere, do the following: 

```
Application macApp = Application.getApplication();
macApp.setQuitHandler(this);

```

and then ,

```
@Override
public void handleQuitRequestWith(AppEvent.QuitEvent qe,final QuitResponse qr) {
    System.out.println("quit clicked");
    qr.performQuit();

}

```

I got hints from CodeGuy and the following url
<http://cr.openjdk.java.net/~michaelm/7113349/jdk8/webrev.4/jdk/raw_files/new/src/macosx/classes/com/apple/eawt/Application.java>