java写出的桌面应用程序如果让图标在系统托盘

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 SystemTrayDemo3 {
	public static void main(String[] args) throws Exception {
		if (!SystemTray.isSupported()) {
			System.out.println("SystemTray is not supported");
			return;
		}
		SystemTray tray = SystemTray.getSystemTray();
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		Image image = toolkit.getImage("F:\\a.jpg");
		PopupMenu menu = new PopupMenu();
		MenuItem messageItem = new MenuItem("关于");
		messageItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "您好朋友");
			}
		});
		menu.add(messageItem);
		MenuItem closeItem = new MenuItem("退出");
		closeItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		menu.add(closeItem);
		TrayIcon icon = new TrayIcon(image, "托盘演示", menu);
		icon.setImageAutoSize(true);
		tray.add(icon);
	}
}

你可能感兴趣的:(java,swing,F#)