Thomas Fritsch said:
I'm not familiar with Java on Mac. But I assume Apple+Q (on the Mac) is the
equivalent of Alt+F4 (on MS-Windows).
How does your java application react on Windows when you hit Alt+F4 ?
I assume it exits immediately, without giving java a chance to prompt the
user to save his/her data.
If my two assumptions above are correct, then you can handle these events in
a cross-platform way. I vaguely remember, that you have to do something
like this:
yourFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
yourFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (....)
// pop up a message "Do you want to save?"
else
System.exit(0);
}
});
You should find the details by searching the groups comp.lang.java.* for
"Alt+F4" and "setDefaultCloseOperation".
I'm afraid your assumptions are not valid. Alt-F4 is a "close window"
command on Windows. The "Apple" key is properly referred to in the Mac
community as the Command key, and Command-Q is the common keyboard
equivalent for exiting an application, analogous to File/Exit in most
Windows applications. Where Windows uses the Control key for many
keyboard equivalents (Ctrl-C, Ctrl-X, etc.), the Mac often uses the
Command key instead (Command-C, Command-X, etc.).
Mac OS X automatically provides every application with an "application
menu" bearing the application's name. This menu includes an About menu
item and a Quit menu item (with Command-Q assigned as its shortcut, in
Java terms). This is what the OP is bumping up against.
It would be a good idea to visit Apple's own Java pages. I would start
with <
http://www.apple.com/java/>, which will redirect to a page with
info on Apple's included Java. The latest OS X includes Java 1.4.2
already installed and 1.5.0 is available. Apple's 1.5 API is at
<
http://developer.apple.com/documentation/Java/Reference/1.5.0/appledoc/a
pi/index.html>, listing Apple's extensions. For the core API, they link
to Sun's own site since Apple's JVM is compliant. Developer information
is at <
http://developer.apple.com/java/>, where documentation links can
be found.
I haven't yet had the opportunity to experiment with making my work app
(currently offered for Windows and Linux) fit into the Mac world. But
to do so, I would suggest looking at the information in the API on the
com.apple.eawt.Application class as a start. The comments at the top
address some of the information that has to be understood in order to
make an app fit into the Mac way of doing things. The unstated but
obvious parts include not providing a File/Exit menu on the Mac, or a
Help/About item, but instead attributing their behaviors to the ones
provided. And there's other info available on some properties that will
be helpful to cause the application to use a proper name for the
Application menu (rather than "java" or a qualified package.class name).
HTH.
= Steve =