final TrayIcon trayIcon;
this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
if (SystemTray.isSupported())
{
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("./images/sms-icon.jpg");
MouseListener mouseListener = new MouseListener()
{
public void mouseClicked(MouseEvent e)
{
//System.out.println("Tray Icon - Mouse clicked!");
}
public void mouseEntered(MouseEvent e)
{
//System.out.println("Tray Icon - Mouse entered!");
}
public void mouseExited(MouseEvent e)
{
//System.out.println("Tray Icon - Mouse exited!");
}
public void mousePressed(MouseEvent e)
{
//System.out.println("Tray Icon - Mouse pressed!");
}
public void mouseReleased(MouseEvent e)
{
//System.out.println("Tray Icon - Mouse released!");
}
};
ActionListener exitListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//System.out.println("Exiting...");
int reply=javax.swing.JOptionPane.showConfirmDialog(rootPane, "Are you sure you want exit?","SMS Manager",1);
if(reply==0)
System.exit(0);
}
};
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Exit");
defaultItem.addActionListener(exitListener);
popup.add(defaultItem);
trayIcon = new TrayIcon(image, "SMS Manager", popup);
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// double click
setVisible(true);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(mouseListener);
try
{
tray.add(trayIcon);
}
catch (AWTException e)
{
System.err.println("TrayIcon could not be added.");
}