package com.tjyx.frame;

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.SystemTray;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import com.tjyx.frame.common.swap.Swap;
import com.tjyx.frame.eventAction.MyWindownListener;
import com.tjyx.frame.myView.JXPanel;
import com.tjyx.frame.myView.JXTrayIcon;
import com.tjyx.resource.XImageIcon;

/**
 * 突击英雄自动领礼包
 * 
 * @author yangtao
 *
 */
public class MyFrame extends JFrame {

	/**
	 * 版本标示
	 */
	private static final long serialVersionUID = -2122161377842820073L;

	private JPanel contentPanel;// 内容窗格

	/**
	 * 构造函数
	 */
	public MyFrame() {
		super();
		
		// 中央内容层,重点处理
		contentPanel = (JPanel) this.getContentPane();// 把内容窗格转化为JPanel
		JPanel centerPanel=new JXPanel("background.jpg");//带背景的JPanel
		contentPanel.add(centerPanel, BorderLayout.CENTER);// 设置界面的背景和界面内容
		setIconImage(new XImageIcon("logo.png").getImg().getImage());// 软件图标
		setTitle("《突击英雄》自动领礼包机");// /软件标题
		setSize(620, 520);// 软件初始界面大小
		addWindowListener(new MyWindownListener());
		
		// 在托盘放上软件图标,自己实现了带图片的托盘弹出右键菜单
		JXTrayIcon tray = new JXTrayIcon((new XImageIcon("Trayicon.png")).getImg().getImage());
		tray.setJPopupMenu(this.createJPopupMenu());
		tray.setToolTip("《突击英雄》自动领礼包机 1.0 \n重庆工程学院\n软件工程系 1300161班 杨淘\nQQ&TEL:18883188003");
		try {
			SystemTray.getSystemTray().add(tray);
		} catch (AWTException e) {
			e.printStackTrace();
		}
		// 双击右下角图标事件
		tray.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					// 判断窗体是否存在
					if (isVisible() == false) {
						setVisible(true);
						setExtendedState(NORMAL);
					} else {
						setVisible(false);
					}
				}
			}
		});
		
		setLocationRelativeTo(null);// 设置软件启动时默认居中
		setVisible(true);// 软件可见
	}

	// 自定义实现的右下角托盘菜单,还有对应的选项事件监听
	JPopupMenu createJPopupMenu() {
		final JPopupMenu popupMenu = new JPopupMenu();
		JMenuItem[] menuItems = new JMenuItem[2];
		String[] menuItemsIcon = { "guanyu.png", "Trayexit.png" };
		String[] menuItemsName = {  "关于", "退出" };
		for (int i = 0; i < menuItemsIcon.length; i++) {
			menuItems[i] = new JMenuItem(menuItemsName[i], new XImageIcon(menuItemsIcon[i]).getImg());
			menuItems[i].addActionListener(Swap.action);
			popupMenu.add(menuItems[i]);
		}
		return popupMenu;
	}
}
最近下载更多
yongzheng132  LV17 2019年6月21日
规范化  LV34 2019年6月21日
HSZ452200852  LV1 2018年9月30日
Smail_  LV19 2017年4月1日
248196826  LV13 2017年2月21日
Yuancc  LV21 2016年12月12日
liruiu5  LV1 2016年10月11日
b750101140  LV1 2015年7月18日
rxw4703  LV14 2015年6月18日
dafang  LV12 2015年5月18日
最近浏览更多
3334004690  LV3 3月6日
xp95323  LV14 2023年11月27日
hougui  LV1 2023年6月20日
17683946472  LV9 2023年6月8日
qq1176648922  LV6 2022年11月10日
2206371875  LV7 2021年12月14日
heiqiang198603  LV1 2021年12月9日
任星浩  LV1 2021年11月18日
yin出门买了吗了  LV9 2021年11月16日
最代码-宋家辉  LV61 2021年11月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友