final?JFrame?frame?=?...;
企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對外擴展宣傳的重要窗口,一個合格的網(wǎng)站不僅僅能為公司帶來巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺,成都創(chuàng)新互聯(lián)面向各種領(lǐng)域:成都混凝土攪拌罐車等成都網(wǎng)站設(shè)計公司、全網(wǎng)營銷推廣解決方案、網(wǎng)站設(shè)計等建站排名服務(wù)。
button.addActionListener(new?ActionListener(){
@Override?public?void?actionPerformed(ActionEvent?e){
frame.setExtendedState(JFrame.ICONIFIED);
}
});
兩個思路
做兩個按鈕,兩個功能分別寫在兩個按鈕上,點擊其中一個控制另一個的現(xiàn)實與隱藏
做一個標志位紀錄點擊次數(shù),根據(jù)次數(shù)奇偶數(shù),或者其它條件控制執(zhí)行內(nèi)容.
最小化時隱藏,在圖標上點右右鍵選擇顯示窗口時,讓窗口顯示出來 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()); }責任編輯:小草