Import java.awt.AWTException;
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.JFrame;
public class Mysystemtray extends jframe{public mysystemtray () {init ();
public void init () {this.setsize (300, 200);
This.setlocationrelativeto (NULL);
This.settray ();
This.setvisible (TRUE);
//Add pallet display: 1. First determine if the current platform supports pallet display public void Settray () {if (systemtray.issupported ()) {/////Determine whether the current platform supports pallet functionality//Create pallet instances
Systemtray tray = Systemtray.getsystemtray (); Create tray Icon: 1. Display icon Image 2. Stop tip text 3. pop-up menu PopupMenu 4. Create a tray icon instance//1
Etimage ("trayiconimage/clienticon.jpg");
2. Stop hint text String = "Mysystemtray";
3. Pop-up menu PopupMenu popupmenu popmenu = new PopupMenu ();
MenuItem Itmopen = new MenuItem ("open"); Itmopen. addActionListener (New ActionListener () {public void actionperformed (ActionEvent e) {show ();
}
});
MenuItem itmhide = new MenuItem ("hidden");
Itmhide.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {unvisible ();
}
});
MenuItem itmexit = new MenuItem ("Exit");
Itmexit.addactionlistener (new ActionListener () {public void actionperformed (ActionEvent e) {Exit ();
}
});
Popmenu.add (Itmopen);
Popmenu.add (Itmhide);
Popmenu.add (Itmexit);
Create tray icon TrayIcon TrayIcon = new TrayIcon (image,text,popmenu);
Add the tray icon to the tray to try {tray.add (TrayIcon);
catch (Awtexception E1) {e1.printstacktrace ();
The external class (this cannot point to) public void unvisible () {this.setvisible (false) cannot be directly invoked in the inner class.
public void Show () {this.setvisible (true);
public void Exit () {system.exit (0);
public static void Main (string[] args) {new Mysystemtray (); }
}
Source: http://csuliunian.iteye.com/blog/1154407