The Java on Mac OS X About,Quit and
Preferences menu items and events
Submitted by alvin on February 9, 2010 - 10:14pm
When writing Java GUI code for the Mac OS X platform, you'll want to
properly handle the Mac
About
,
Quit
, and
Preferences
menu items and events.
Fortunately doing this is very simple, and I'll demonstrate that in this
"Java on Mac OS X" tutorial.
The Mac Application and ApplicationAdapter
classes
The key behind properly handling the About, Quit, and Preferences menu
items and events comes from using Apple's Application and
ApplicationAdapter classes. Using the source code from a Java/Mac
application I just created, let's look at how this works.
The Mac ApplicationAdapter classes
We build a handler for the Mac OS X About, Quit, and Preferences events
by extending the Mac ApplicationAdapter class. As you can see from the
source code below, when I handle the "Quit" event I close the application
with System.exit; and when I receive an About or Preferences event, I
display a dialog in response to those events.
In your Java/Mac application you will handle these events differently,
this is really all we have to do with the Mac ApplicationAdapter class.
package com.devdaily.desktopshield;
import javax.swing.JOptionPane;
import com.apple.eawt.ApplicationAdapter;
import com.apple.eawt.ApplicationEvent;
/**
* MacAdapter.java
* Copyright 2010, Alvin J. Alexander, devdaily.com.
*