當前位置:編程學習大全網 - 源碼下載 - Qt如何獲取系統托盤的鼠標進出事件?

Qt如何獲取系統托盤的鼠標進出事件?

JDK6/mq612 */ public類TrayDemo擴展JFrame { private JPanel pane = nullprivate JButton button = null//啟動托盤圖標的按鈕private JLabel label = null//用於顯示系統是否支持托盤的信息;private TrayIcon trayIcon = null//托盤圖標私有系統托盤托盤= null//操作系統托盤公共托盤demo () {super ("Java 1.6.0托盤技術演示")的例子;請嘗試{//將LookAndFeel設置為Windows樣式的UIMANAGER。設置觀感(" com . sun . Java . swing . plaf . windows . windows觀感");} catch(Exception ex){ ex . printstacktrace();} pane = new JPanel();Button = new JButton("收縮到托盤");button . set enabled(false);Label = new JLabel("此操作系統不支持托盤");pane.add(標簽);pane.add(按鈕);If(system tray . issupported()){//如果操作系統支持托盤this . tray();} this.getContentPane()。添加(窗格);this . setdefaultcloseoperation(JFrame。EXIT _ ON _ CLOSE);this.setSize(300,200);this . set visible(true);}/* * *托盤相關代碼*/private void tray(){ label . settext("本操作系統支持托盤");button . set enabled(true);tray = system tray . getsystem tray();//獲取操作系統托盤image icon icon = new image icon(" images/icon . gif ")的壹個實例;//icon PopupMenu pop =要在托盤中顯示的新popup menu();//構造壹個右鍵彈出菜單MenuItem show = new MenuItem("顯示窗口");MenuItem exit = new MenuItem("退出演示");MenuItem Author = new MenuItem(" Author ");/** * TrayIcon有三種結構* TrayIcon(Image image)用“Icon”構造* TrayIcon(Image image,string tooltip)用圖標和工具提示構造* Trayicon (image image,String ToolTip,popup menu popup)用圖標和工具提示,“pop-up menu”構造壹個托盤圖標*/tray icon = new tray icon(icon . getimage(),“Java 1.6.0托盤技術演示”,pop);//點擊此按鈕,窗口將被關閉。托盤圖標被添加到系統按鈕的托盤中。AddActionListener(New Action Listener(){ Public Void Action Performed(Action event e){ Try { Tray。添加(tray icon);//將托盤圖標添加到系統的托盤實例中,並設置visible(false);//使窗口不可見} catch (awtexception ex) {ex。printstacktrace();} } });/* * *添加鼠標偵聽器。當鼠標雙擊托盤圖標時,默認顯示窗口*/trayicon。addmouselistener(新鼠標適配器(){公共void鼠標被單擊(鼠標事件e))。{if(e.getClickCount()==2){ //雙擊tray . remove(tray icon);//從系統的托盤實例中移除托盤圖標setVisible(true );//顯示窗口} });展示。AddActionListener(New Action Listener()){//單擊“顯示窗口”菜單,將顯示窗口。已執行公共Void操作(ActionEvent E) {Tray。移除(tray icon);//從系統的托盤實例中移除托盤圖標setVisible(true );//顯示窗口} });退出. a
  • 上一篇:中國燃氣熱水器前十名
  • 下一篇:蘋果手機木馬怎麽辦?
  • copyright 2024編程學習大全網