Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: How to Ue system tray

Java: How to Ue system tray
{filelink=995}

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 SystemTray{
  public static void main(String[] args)throws Exception {
    if (!SystemTray.isSupported()) {
      System.out.println("SystemTray Exception");
      return;
    }
    SystemTray tray = SystemTray.getSystemTray();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("icon.jpg");
    PopupMenu menu = new PopupMenu();
    MenuItem message = new MenuItem("your message");
    message.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(null, "Thank you");
      }
    });
    menu.add(message);
    MenuItem fermer = new MenuItem("Close");
    fermer.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
      }
    });
    menu.add(fermer);
    TrayIcon icon = new TrayIcon(image, "Example", menu);
    icon.setImageAutoSize(true);
    tray.add(icon);
  }
}

Users who found this page were searching for:

  • java get systray object import

No comments yet.

Leave a Comment