夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          package test;

          import java.awt.Frame;
          import java.awt.Image;
          import java.awt.SystemTray;
          import java.awt.Toolkit;
          import java.awt.TrayIcon;
          import java.awt.event.MouseAdapter;
          import java.awt.event.MouseEvent;
          import java.awt.event.WindowAdapter;
          import java.awt.event.WindowEvent;

          import javax.swing.JFrame;

          @SuppressWarnings(
          "serial")
          public class MyFrame extends JFrame
          {
              
          public MyFrame()
              
          {
                  
          super("MY FRAME");
                  
          this.init();
              }

              
              
          private void init()
              
          {
                  
          this.setSize(400300);
                  Image icons 
          = getToolkit().getImage(this.getClass().getResource("/icons/cc.gif"));
                  
          this.setIconImage(icons);
                  
          double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
                  
          double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
                  
          this.setLocation((int) (width - this.getWidth()) / 2, (int) (height - this.getHeight()) / 2);
                  
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  
          // 托盤
                  TrayIcon trayIcon = new TrayIcon(icons, "MY FRAME");
                  
          try
                  
          {
                      SystemTray.getSystemTray().add(trayIcon);
                  }

                  
          catch (Exception ex)
                  
          {}
                  
                  
          // 托盤事件-最小化
                  this.addWindowListener(new WindowAdapter()
                      
          {
                          
          public void windowIconified(WindowEvent e)
                          
          {
                              
          // 窗口最小化時dispose該窗口
                              dispose();
                          }

                      }
          );
                  
                  
          //托盤事件-雙擊托盤最大化
                  trayIcon.addMouseListener(new MouseAdapter()
                      
          {
                          
          public void mouseClicked(MouseEvent e)
                          
          {
                              
          // 雙擊托盤窗口再現
                              if (e.getClickCount() == 2)
                              
          {
                                  setExtendedState(Frame.NORMAL);
                              }

                              setVisible(
          true);
                          }

                      }
          );
                  
          this.setResizable(false);
                  
          this.setVisible(true);
              }

              
              
          public static void main(String[] args)
              
          {
                  
          new MyFrame();
              }

          }

          posted on 2010-10-09 16:38 HUIKK 閱讀(201) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 军事| 泽州县| 固安县| 荣成市| 襄垣县| 延寿县| 邯郸市| 洛宁县| 静宁县| 辽源市| 南皮县| 措美县| 体育| 屏山县| 大姚县| 巧家县| 金堂县| 宁波市| 枣庄市| 任丘市| 什邡市| 新竹县| 三台县| 观塘区| 邵东县| 科技| 呼和浩特市| 长宁区| 三亚市| 滨州市| 叶城县| 阜阳市| 广汉市| 彭阳县| 四平市| 突泉县| 娄烦县| 克山县| 长阳| 军事| 区。|