minimize button and system tray
Hello
When i push the minimize button i would like to do a
Code:
myFrame.setState ( Frame.ICONIFIED );
but the question is, where do i write this?
also, i would like my application the go to system tray:
Code:
public void systemTray() {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("sdu.gif");
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Exiting...");
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "Tray Demo", popup);
trayIcon.setImageAutoSize(true);
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.err.println("TrayIcon could not be added.");
}
}
}
but when i put the method in the main method, is says:
non-static method systemTray() cannot be referenced from a static contex
How do i fix this? thanks! :)