十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
final JFrame frame = ...;
企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,成都创新互联面向各种领域:成都混凝土搅拌罐车等成都网站设计公司、全网营销推广解决方案、网站设计等建站排名服务。
button.addActionListener(new ActionListener(){
@Override public void actionPerformed(ActionEvent e){
frame.setExtendedState(JFrame.ICONIFIED);
}
});
两个思路
做两个按钮,两个功能分别写在两个按钮上,点击其中一个控制另一个的现实与隐藏
做一个标志位纪录点击次数,根据次数奇偶数,或者其它条件控制执行内容.
最小化时隐藏,在图标上点右右键选择显示窗口时,让窗口显示出来 import java.awt.AWTException; import java.awt.Image; import java.awt.MenuItem; import java.awt.SystemTray; import java.awt.Toolkit; import java.awt.TrayIcon; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class SystemTrayTest extends Thread { TrayIcon st; SystemTray tray =null; //javax.swing.Popup p; java.awt.PopupMenu popup; MenuItem mi1,mi2; msgbox m=null; public void getm(msgbox m){ this.m=m; } public void run() { // TODO Auto-generated method stub super.run(); if (SystemTray.isSupported()) { // get the SystemTray instance tray = SystemTray.getSystemTray(); // load an image String test = System.getProperty("user.dir").replace('\\', '/'); BufferedImage src = null; try { src = ImageIO.read(new File(test + "\\logo.jpg")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 读入源图像 // Image image = Toolkit.getDefaultToolkit().getImage(test + "\\logo.jpg"); // create a action listener to listen for default action executed on // the tray icon popup=new java.awt.PopupMenu(); mi1=new MenuItem("显示窗口"); mi2=new MenuItem("---"); popup.add(mi1); popup.add(mi2); mi1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub m.setVisible(true); System.out.println("open"); } }); mi2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub //System.out.println("close"); //System.exit(0); } }); st = new TrayIcon(image, "Tray Demo", popup); try { tray.add(st); } catch (AWTException e) { e.printStackTrace(); } } } public static void main(String[] args) { new SystemTrayTest().start(); } } //使窗口最小化,并隐藏 public void windowIconified(WindowEvent e) { System.out.print("sssssss"); jf.setVisible(false); System.out.print(""+e+" "+e.getClass()+" "+e.getNewState()); }责任编辑:小草