梦幻之旅

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 阅读(196) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: