package com;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends Frame {
private static final long serialVersionUID = 1L;
private static test frame;
private ImageIcon ii;// 创建托盘图标
private TrayIcon ti;
private SystemTray st;
private test() {
ii = new ImageIcon("http://www.huomo.cn/developer/img.jpg");
this.setResizable(false);
this.setIconImage(ii.getImage());
this.setBackground(new Color(0x333333));
this.setSize(500, 500);
this.run();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
frame.dispose();
System.exit(0);
}
public void windowIconified(WindowEvent e) {
if (SystemTray.isSupported() == true) {
frame.setVisible(false);
try {
st.add(ti);
} catch (Exception e1) {
}
}
}
});
this.setVisible(true);
}
public void run() {
if (SystemTray.isSupported() == true)// 判断当前平台是否支持系统托盘。
{
ti = new TrayIcon(ii.getImage(), "最小化到托盘");// 初始化托盘图标
st = SystemTray.getSystemTray();// 获取表示桌面托盘区的 SystemTray 实例。
ti.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
frame.setVisible(true);
frame.setExtendedState(NORMAL);
try {
st.remove(ti);
} catch (Exception ee) {
}
}
}
});
}
}
public static void main(String[] args)
{
frame = new test();
}
}