posts - 39,  comments - 263,  trackbacks - 0

          swt 簡單的托盤程序
          java寫和操作系統相關的程序難度非常大。在java 6出現之前,如果你想實現一個托盤程序,最簡單的就是用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);
          知道了重點,事情變的很簡單了。看看所有程序
          //-----------------
          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的類。具體操作你搜索一下吧。
          但是上面的代碼只是加入了托盤,這可能是最簡單的實現托盤的程序了。我們加入事件處理,讓程序能夠最大和最小化。然后把托盤用圖片來表示。
          詳細的代碼不參考
          下載 到eclipse里運行

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

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

          完整的例子請看
          強!簡潔!SWT實現任務欄圖標(系統托盤),帶菜單和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 到托盤的插件(原創,源碼)
          這是 SWT 托盤功能的實用實現, 相關代碼在 EclipseTraySingleton.java 中
          http://www.aygfsteel.com/beansoft/archive/2007/01/03/88465.html
          Tomcat服務器監控1.2版 for Win,Linux(原創)
          這里面用的是 Sun 的 JDIC 組件做的 Swing 版本的托盤, 代碼在 TrayIndicator.java 中.  回復  更多評論
            
          # re: swt 簡單的托盤程序
          2007-01-08 12:22 | 云淡風輕
          以為這里你已經置之不理了呢  回復  更多評論
            
          # re: swt 簡單的托盤程序
          2008-03-29 12:46 | bin
          謝謝老大 正找這個  回復  更多評論
            

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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          <2007年1月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(18)

          我參與的團隊

          隨筆檔案(39)

          收藏夾(1)

          搜索

          •  

          積分與排名

          • 積分 - 451361
          • 排名 - 119

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 罗定市| 仙桃市| 武陟县| 正宁县| 璧山县| 桃园县| 安丘市| 府谷县| 梁平县| 志丹县| 辽宁省| 巴马| 莒南县| 鄂伦春自治旗| 新乡市| 集安市| 荔波县| 浙江省| 子洲县| 长子县| 沅江市| 扎鲁特旗| 章丘市| 崇左市| 台东县| 苏尼特右旗| 邓州市| 墨脱县| 辽宁省| 德惠市| 宝丰县| 汝州市| 东兰县| 固始县| 大埔县| 樟树市| 句容市| 措勤县| 光山县| 桐庐县| 皋兰县|