代码如下:
package prj_trayicon;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class FrmTrayIcon extends JFrame
{
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
TrayIcon ti;
PopupMenu popupMenu1 = new PopupMenu();
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
public FrmTrayIcon()
{
try
{
setDefaultCloseOperation(HIDE_ON_CLOSE);
jbInit();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
contentPane = (JPanel)getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(400, 300));
setTitle( "TrayIcon ");
this.addWindowListener(new FrmTrayIcon_this_windowAdapter(this));
jButton1.setText( "Exit ");
jButton1.addActionListener(new FrmTrayIcon_jButton1_actionAdapter(this));
contentPane.add(jButton1, new XYConstraints(68, 48, -1, -1));
menuItem1.setLabel( "Show ");
menuItem1.addActionListener(new FrmTrayIcon_menuItem1_actionAdapter(this));
menuItem2.setLabel( "Exit ");
menuItem2.addActionListener(new FrmTrayIcon_menuItem2_actionAdapter(this));
popupMenu1.add(menuItem1);
popupMenu1.add(menuItem2);
Image image = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource( "TrayIcon.png "));
ti = new TrayIcon(image, "TrayIcon ", popupMenu1);
}
public void jButton1_actionPerformed(ActionEvent e)
{
System.exit(0);
}
public void this_windowClosing(WindowEvent e)
{
if (SystemTray.isSupported())
{
setVisible(false);
MiniToTray();
}