which event can i catch, when my application is closed by the system?
Hello,
I have an application that I put in the taskbar. I want the application to react (write in a log file), when it's being closed.
with an actionListener, I can catch the event when the user terminates the application.
but which event can I catch, when the system closes the application when it shuts down?
I allready tried to make a JFrame of it and put a windowListener on it, to catch windowClosing, but that doesn't work.
Any Idea?
For the moment I use the following code .
--CODE SNIPLET-
Logger(){
TrayIcon trayIcon = null;
if (SystemTray.isSupported()) {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();
// load an image
Image image = Toolkit.getDefaultToolkit().getImage(strImage);
// create a popup menu
PopupMenu popup = new PopupMenu();
// create menu items for the default action
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { closing();}
});
popup.add(exitItem);
// construct a TrayIcon
trayIcon = new TrayIcon(image, "Logger", popup);
// add the tray image
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println(e);
}
}
}
public void closing() {
String text = "something to say";
writeLogEntry(text);
System.exit(0);
}
Message was edited by:
thomasfournier

