java托盘程序实例

import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class TrayTest {
	static Image image = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");
	static TrayIcon trayIcon = new TrayIcon(image,"测试托盘图标");


	public static void main(String[] args) {
		if(SystemTray.isSupported()){
			SystemTray tray = SystemTray.getSystemTray();
			trayIcon.setImageAutoSize(true);//设置自动调整大小的属性。
			trayIcon.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					System.out.println("在这儿呢?");
					//displayMessage:在托盘图标附近显示弹出消息。
//TrayIcon.MessageType   java.awt 确定哪个图标将显示在消息标题中,以及消息根据显示生成的可能的系统声音。
					trayIcon.displayMessage("测试者", "你能看到什么?",TrayIcon.MessageType.INFO);
				}
			});

			try{
				tray.add(trayIcon);
			}catch(AWTException e){
				e.printStackTrace();
			}
		}
	}

}


转载至:http://blog.csdn.net/youyigong/article/details/6845381

你可能感兴趣的:(java托盘)