首页 > 代码库 > Java单击图标实现显示Frame界面

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

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界面