|
Q: My Java 1.4 application has an ApplicationListener with a handleAbout method, but the default about box still appears over my own when "About MyApp" is selected from the Application menu. Why?A: The problem here is that the Below is a simplified example of a proper Listing 1: Suppressing the default aboutBox using setHandled(true).
public void handleAbout(ApplicationEvent e) {
new AboutBox().show();
// Tell eAWT you've handled the request, disabling the default about box.
e.setHandled(true);
}
A similar problem may occur with the Listing 2: Authorizing a quit using setHandled(true).
public void handleQuit(ApplicationEvent e) {
cleanupResources();
// The quit request is handled; proceed with app termination
e.setHandled(true);
}
If you wish to have complete control over the quit and call Listing 3: Rejecting a quit using setHandled(false).
public void handleQuit(ApplicationEvent e) {
// Reject the quit request and handle it as we see fit
e.setHandled(false);
String msg = "Are you sure you want to quit?"
int result = JOptionPane.showConfirmDialog(mainFrame, msg);
if (result == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
Note: This Q&A refers to the eAWT APIs that were introduced with Java 1.4.1 on Mac OS X. For information on quit events in Java 1.3, please see Technical Q&A 1187. Note: The about and quit events are the only eAWT events that require handling; other methods such as Document Revision History
Posted: 2004-08-31 |
|