import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
public class Main {
static TrayIcon trayIcon = null;
public static void main(String[] args) throws Exception {
SystemTray sysTray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("/a.jpg");
ActionListener exitListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Bye from the tray");
System.exit(0);
}
};
ActionListener executeListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "!", "User action",
JOptionPane.INFORMATION_MESSAGE);
trayIcon.displayMessage("Done", "!", TrayIcon.MessageType.INFO);
}
};
PopupMenu menu = new PopupMenu();
MenuItem execItem = new MenuItem("Action...");
execItem.addActionListener(executeListener);
menu.add(execItem);
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(exitListener);
menu.add(exitItem);
trayIcon = new TrayIcon(image, "Java System Tray Demo", menu);
trayIcon.setImageAutoSize(true);
sysTray.add(trayIcon);
trayIcon.displayMessage("Ready", "started", TrayIcon.MessageType.INFO);
}
}