posts - 39,  comments - 263,  trackbacks - 0

          swt 簡單的托盤程序
          java寫和操作系統(tǒng)相關的程序難度非常大。在java 6出現(xiàn)之前,如果你想實現(xiàn)一個托盤程序,最簡單的就是用swt了。
          通過google我找到了一段代碼。
          其實很簡單。主要的代碼如下:
          ?????????????final Tray tray = display.getSystemTray();
          ??????????? final TrayItem trayItem = new TrayItem(tray, SWT.NONE);
          ??????????? Image image = new Image (display, 16, 16);
          ??????????? trayItem.setImage(image);
          知道了重點,事情變的很簡單了??纯此谐绦?br />//-----------------
          public class SystemTray extends Shell {
          ??? public static void main(String args[]) {
          ??????? try {
          ??????????? Display display = Display.getDefault();
          ??????????? SystemTray shell = new SystemTray(display, SWT.SHELL_TRIM);
          ?????????? // shell.createSystemTray(shell);
          ??????????? final Tray tray = display.getSystemTray();
          ??????????? final TrayItem trayItem = new TrayItem(tray, SWT.NONE);
          ??????????? Image image = new Image (display, 16, 16);
          ??????????? trayItem.setImage(image);
          ??????????? shell.open();
          ??????????? shell.layout();
          ??????????? while (!shell.isDisposed()) {
          ??????????????? if (!display.readAndDispatch())
          ??????????????????? display.sleep();
          ??????????? }
          ??????? } catch (Exception e) {
          ??????????? e.printStackTrace();
          ??????? }
          ??? }
          ??? public SystemTray(Display display, int style) {
          ??????? super(display, style);
          ??????? createContents();
          ??? }

          ??? /**
          ???? * Create contents of the window
          ???? */
          ??? protected void createContents() {
          ??????? setText("SWT Application");
          ??????? setSize(500, 375);

          ??? }
          ??? //swt 默認情況下不允許shell被繼承
          ??? //所以我重載了父類的方法
          ??? protected void checkSubclass() {
          ???????? }
          }
          //--------------------
          如果你想成功運行以上代碼,你最好在eclipse下新建一個swt的類。具體操作你搜索一下吧。
          但是上面的代碼只是加入了托盤,這可能是最簡單的實現(xiàn)托盤的程序了。我們加入事件處理,讓程序能夠最大和最小化。然后把托盤用圖片來表示。
          詳細的代碼不參考
          下載 到eclipse里運行

          posted on 2007-01-03 22:58 nake 閱讀(3423) 評論(4)  編輯  收藏

          FeedBack:
          # re: swt 簡單的托盤程序
          2007-01-04 09:17 | 交口稱贊
          你最好在eclipse下新建一個swt的類??
          請把意思表達清楚

          完整的例子請看
          強!簡潔!SWT實現(xiàn)任務欄圖標(系統(tǒng)托盤),帶菜單和ToolTip
          http://www.aygfsteel.com/vip01/archive/2006/12/26/90127.html  回復  更多評論
            
          # re: swt 簡單的托盤程序
          2007-01-04 09:41 | BeanSoft
          ..... http://www.aygfsteel.com/beansoft/archive/2007/01/02/91377.html Eclipse Tray 1.0 RC1 - 最小化 Eclipse 到托盤的插件(原創(chuàng),源碼)
          這是 SWT 托盤功能的實用實現(xiàn), 相關代碼在 EclipseTraySingleton.java 中
          http://www.aygfsteel.com/beansoft/archive/2007/01/03/88465.html
          Tomcat服務器監(jiān)控1.2版 for Win,Linux(原創(chuàng))
          這里面用的是 Sun 的 JDIC 組件做的 Swing 版本的托盤, 代碼在 TrayIndicator.java 中.  回復  更多評論
            
          # re: swt 簡單的托盤程序
          2007-01-08 12:22 | 云淡風輕
          以為這里你已經(jīng)置之不理了呢  回復  更多評論
            
          # re: swt 簡單的托盤程序
          2008-03-29 12:46 | bin
          謝謝老大 正找這個  回復  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(18)

          我參與的團隊

          隨筆檔案(39)

          收藏夾(1)

          搜索

          •  

          積分與排名

          • 積分 - 451548
          • 排名 - 119

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 澄江县| 榕江县| 陆河县| 阿合奇县| 潮州市| 尼玛县| 普陀区| 衡东县| 怀远县| 北碚区| 孝义市| 永新县| 花莲市| 阳高县| 乌拉特中旗| 宁城县| 隆子县| 大埔县| 安乡县| 龙门县| 太谷县| 渭源县| 木里| 铅山县| 农安县| 广元市| 郎溪县| 泽库县| 广昌县| 临夏市| 翁牛特旗| 日土县| 南开区| 高州市| 莎车县| 青冈县| 石狮市| 淄博市| 会昌县| 亳州市| 修武县|