乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Java1.6.0實現(xiàn)系統(tǒng)托盤技術(shù)

       CevenCheng 2010-11-08

      實現(xiàn)系統(tǒng)托盤圖標(biāo),借用dll動態(tài)鏈接庫,用JAVA JNI實現(xiàn)。

            JDK6.0的系統(tǒng)托盤的雛形是個開源的JDIC,實現(xiàn)原理就是不同的系統(tǒng)調(diào)用不同的JNI不是像LZ那樣想的,可以在任何平臺上跑,所以也是分支持不支持的,LZ可以用JDK1.6或JDI。

      1. import java.awt.AWTException;     
      2. import java.awt.MenuItem;     
      3. import java.awt.PopupMenu;     
      4. import java.awt.SystemTray;     
      5. import java.awt.TrayIcon;     
      6. import java.awt.event.ActionEvent;     
      7. import java.awt.event.ActionListener;     
      8. import java.awt.event.MouseAdapter;     
      9. import java.awt.event.MouseEvent;     
      10. import javax.swing.ImageIcon;     
      11. import javax.swing.JButton;     
      12. import javax.swing.JFrame;     
      13. import javax.swing.JLabel;     
      14. import javax.swing.JOptionPane;     
      15. import javax.swing.JPanel;     
      16. import javax.swing.UIManager;     
      17. /**   
      18.  * Java1.6.0實現(xiàn)系統(tǒng)托盤技術(shù)演示   
      19.  */    
      20. public class TrayDemo extends JFrame {     
      21.     private JPanel pane = null;     
      22.     private JButton button = null// 啟動托盤圖標(biāo)的按鈕     
      23.     private JLabel label = null// 用來顯示系統(tǒng)是否支持托盤的信息     
      24.     private TrayIcon trayIcon = null// 托盤圖標(biāo)     
      25.     private SystemTray tray = null// 本操作系統(tǒng)托盤的實例     
      26.     
      27.     public TrayDemo() {     
      28.         super("Java1.6.0托盤技術(shù)演示");     
      29.         try {     
      30.             // 將LookAndFeel設(shè)置成Windows樣式     
      31.             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");     
      32.         } catch (Exception ex) {     
      33.             ex.printStackTrace();     
      34.         }     
      35.         pane = new JPanel();     
      36.         button = new JButton("縮小到托盤");     
      37.         button.setEnabled(false);     
      38.         label = new JLabel("本操作系統(tǒng)不支持托盤");     
      39.         pane.add(label);     
      40.         pane.add(button);     
      41.         if(SystemTray.isSupported()){ // 如果操作系統(tǒng)支持托盤     
      42.             this.tray();     
      43.         }     
      44.         this.getContentPane().add(pane);     
      45.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
      46.         this.setSize(300200);     
      47.         this.setVisible(true);     
      48.     }     
      49.     /**   
      50.      * 托盤相關(guān)代碼   
      51.      */    
      52.     private void tray(){     
      53.         label.setText("本操作系統(tǒng)支持托盤");     
      54.         button.setEnabled(true);     
      55.         tray = SystemTray.getSystemTray(); // 獲得本操作系統(tǒng)托盤的實例     
      56.         ImageIcon icon = new ImageIcon("F:/NetBeansProjects/Desktop/src/38.gif"); // 將要顯示到托盤中的圖標(biāo)     
      57.         PopupMenu pop = new PopupMenu(); // 構(gòu)造一個右鍵彈出式菜單     
      58.         MenuItem show = new MenuItem("顯示窗口");     
      59.         MenuItem exit = new MenuItem("退出演示");     
      60.         MenuItem author = new MenuItem("Author");     
      61.         /**   
      62.          * TrayIcon有三個構(gòu)造   
      63.          * TrayIcon(Image image) 用“圖標(biāo)”來構(gòu)造   
      64.          * TrayIcon(Image image, String tooltip) 用“圖標(biāo)”和“ToolTip”構(gòu)造   
      65.          * TrayIcon(Image image, String tooltip, PopupMenu popup) 用“圖標(biāo)”,“ToolTip”,“彈出菜單”來構(gòu)造一個托盤圖標(biāo)   
      66.          */    
      67.         trayIcon = new TrayIcon(icon.getImage(), "Java1.6.0托盤技術(shù)演示", pop);     
      68.         // 點擊本按鈕后窗口被關(guān)閉,托盤圖標(biāo)被添加到系統(tǒng)的托盤中     
      69.         button.addActionListener(new ActionListener() {     
      70.             public void actionPerformed(ActionEvent e) {     
      71.                 try {     
      72.                     tray.add(trayIcon); // 將托盤圖標(biāo)添加到系統(tǒng)的托盤實例中     
      73.                     setVisible(false); // 使窗口不可視     
      74.                 } catch (AWTException ex) {     
      75.                     ex.printStackTrace();     
      76.                 }     
      77.             }     
      78.         });     
      79.         /**   
      80.          * 添加鼠標(biāo)監(jiān)聽器,當(dāng)鼠標(biāo)在托盤圖標(biāo)上雙擊時,默認顯示窗口   
      81.          */    
      82.         trayIcon.addMouseListener(new MouseAdapter() {     
      83.             public void mouseClicked(MouseEvent e) {     
      84.                 if(e.getClickCount()==2){ // 鼠標(biāo)雙擊     
      85.                     tray.remove(trayIcon); // 從系統(tǒng)的托盤實例中移除托盤圖標(biāo)     
      86.                     setVisible(true); // 顯示窗口     
      87.                 }     
      88.             }     
      89.         });     
      90.         show.addActionListener(new ActionListener() { // 點擊“顯示窗口”菜單后將窗口顯示出來     
      91.             public void actionPerformed(ActionEvent e) {     
      92.                 tray.remove(trayIcon); // 從系統(tǒng)的托盤實例中移除托盤圖標(biāo)     
      93.                 setVisible(true); // 顯示窗口     
      94.             }     
      95.         });     
      96.         exit.addActionListener(new ActionListener() { // 點擊“退出演示”菜單后退出程序     
      97.             public void actionPerformed(ActionEvent e) {     
      98.                 System.exit(0); // 退出程序     
      99.             }     
      100.         });     
      101.         author.addActionListener(new ActionListener() {     
      102.             public void actionPerformed(ActionEvent e) {     
      103.                 showMessage();     
      104.             }     
      105.         });     
      106.         pop.add(show);     
      107.         pop.add(exit);     
      108.         pop.add(author);     
      109.     }     
      110.     /**   
      111.      * 顯示信息   
      112.      */    
      113.     private void showMessage(){     
      114.         JOptionPane.showMessageDialog(thisnew JLabel("<html>作者:voole" +     
      115.                 "<br>Blog:http://voole.</html>"), "voole", JOptionPane.INFORMATION_MESSAGE);     
      116.     }     
      117.     
      118.     public static void main(String[] args) {     
      119.         new TrayDemo();     
      120.     }     
      121.     
      122. }    

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多