码迷,mamicode.com
首页 > 编程语言 > 详细

Java单击图标实现显示Frame界面

时间:2015-01-03 02:01:24      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:

package part17;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ActionEvent4extends JFrame implements ActionListener
{
  private Image image = Toolkit.getDefaultToolkit().createImage("jingji.png");//这里你得//改一下
  private TrayIcon tl = new TrayIcon(image);
  private JButton jb = new JButton();
    public ActionEvent4() throws AWTException 
    {
     super( "单击了托盘图标" );
     SystemTray.getSystemTray().add(tl);
     tl.addActionListener(this);
     tl.addMouseListener(new MouseAdapter() {
         @Override
         public void mouseClicked(MouseEvent e) {
                showView();
         }
     });
    }
    private void showView(){    
        TestActionEvent.this.setVisible(true);
        TestActionEvent.this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        TestActionEvent.this.setSize(400, 300);
  }
  public static void main(String[] args) throws AWTException {
   // TODO Auto-generated method stub
   new ActionEvent4();
  }
@Override
  public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
   if ( e.getSource() == tl ){
     this.setVisible(true);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setSize(400,300);
     }
   }
}

 

Java单击图标实现显示Frame界面

标签:

原文地址:http://www.cnblogs.com/khbcsu/p/4199047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!