📄 main.java.svn-base
字号:
package jm.form.msn.form;import java.awt.AWTException;import java.awt.GridLayout;import java.awt.Image;import java.awt.MenuItem;import java.awt.PopupMenu;import java.awt.SystemTray;import java.awt.TrayIcon;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.File;import javax.imageio.ImageIO;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.SwingConstants;import javax.swing.WindowConstants;import jm.JM;import jm.form.msn.config.JMMRConfigConstants;import jm.form.msn.util.Manager;/** * 主画面 * 梦界家园MSNP15 * * @author ISHome * @since 0.1 * @version 0.5.0.2 */public class Main extends javax.swing.JFrame implements JMMRConfigConstants { private JButton faq; private JButton talk; private JButton test; private JButton run; private JButton exit; private JButton config; private JButton tag; private Manager manager = null; private JButton log; public Main(Manager server) { super(); manager = server; initGUI(); } private void initGUI() { try { GridLayout thisLayout = new GridLayout(1, 1); thisLayout.setColumns(1); thisLayout.setHgap(1); thisLayout.setVgap(1); getContentPane().setLayout(thisLayout); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); { run = new JButton(); getContentPane().add(run); run.setFont(BUTTON_FOUNT); run.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_RUN))); run.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_RUN_TEXT)); run.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_RUN_HELP)); run.setHorizontalAlignment(SwingConstants.LEFT); run.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { runServer(); } }); } { config = new JButton(); getContentPane().add(config); config.setFont(BUTTON_FOUNT); config.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_CONFIG))); config.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_CONFIG_TEXT)); config.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_CONFIG_HELP)); config.setHorizontalAlignment(SwingConstants.LEFT); config.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Config form = new Config(manager.getMainForm(), manager); setVisible(false); manager.openFrame(form); if (ti != null) SystemTray.getSystemTray().remove(ti);// 从系统托盘中移出 manager.loadConfigMap(); manager.runMainForm(); } }); } { tag = new JButton(); getContentPane().add(tag); tag.setFont(BUTTON_FOUNT); tag.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_TAG))); tag.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TAG_TEXT)); tag.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TAG_HELP)); tag.setHorizontalAlignment(SwingConstants.LEFT); tag.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Tag form = new Tag(manager.getMainForm(), manager); manager.openFrame(form); } }); } { talk = new JButton(); getContentPane().add(talk); talk.setFont(BUTTON_FOUNT); talk.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_TALK))); talk.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TALK_TEXT)); talk.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TALK_HELP)); talk.setHorizontalAlignment(SwingConstants.LEFT); talk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TalkList form = new TalkList(manager.getMainForm(), manager); manager.openFrame(form); } }); } { // 组织使用 if (CONFIG_SYSTEM_TYPE_ORGANIZATION.equals(manager.getConfigMap().get(CONFIG_SYSTEM_TYPE))) { faq = new JButton(); getContentPane().add(faq); faq.setFont(BUTTON_FOUNT); faq.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_FAQ))); faq.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_FAQ_TEXT)); faq.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_FAQ_HELP)); faq.setHorizontalAlignment(SwingConstants.LEFT); faq.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FaqList form = new FaqList(manager.getMainForm(), manager); manager.openFrame(form); } }); } } { log = new JButton(); getContentPane().add(log); log.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_LOG))); log.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_LOG_TEXT)); log.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_LOG_HELP)); log.setHorizontalAlignment(SwingConstants.LEFT); log.setFont(BUTTON_FOUNT); log.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { manager.openFrame(manager.getLogForm()); } }); } { test = new JButton(); getContentPane().add(test); test.setFont(BUTTON_FOUNT); test.setForeground(new java.awt.Color(0, 0, 255)); test.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_TEST))); test.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TEST_TEXT)); test.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_TEST_HELP)); test.setHorizontalAlignment(SwingConstants.LEFT); test.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TestSystem form = new TestSystem(manager.getMainForm(), manager); manager.openFrame(form); } }); } { exit = new JButton(); getContentPane().add(exit); exit.setIcon(new ImageIcon(manager.getConfigMap().get(STYLES_MAIN_FORM_EXIT))); exit.setText(manager.getConfigMap().get(LANG_MAIN_BUTTON_EXIT_TEXT)); exit.setToolTipText(manager.getConfigMap().get(LANG_MAIN_BUTTON_EXIT_HELP)); exit.setHorizontalAlignment(SwingConstants.LEFT); exit.setFont(BUTTON_FOUNT); exit.setForeground(new java.awt.Color(255, 0, 0)); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeServer(); } }); } { this.setTitle(JM.Name + " " + JM.Ver); this.getContentPane().setBackground(new java.awt.Color(255, 255, 255)); this.addWindowListener(new WindowAdapter() { /** * 窗口正处在关闭过程中时调用。此时可重写关闭操作。 * * @param e */ public void windowClosing(WindowEvent e) { closeServer(); } /** * 图标化窗口时调用。 */ public void windowIconified(WindowEvent e) { if (SystemTray.isSupported()) { setVisible(false);// 隐藏窗口 minimizeToTray();// 如果系统支持托盘图标,将窗口放入系统托盘区 if (ti != null) ti.displayMessage(JM.Name, manager.getConfigMap().get(LANG_MAIN_TRAY_MIN_TEXT), TrayIcon.MessageType.INFO); } } }); // 配置系统图标 this.setIconImage(ImageIO.read(new File(manager.getConfigMap().get(IMG_SYSTEM_LOGO)))); // this.setSize(800, 65); this.setResizable(false); // 使用系统托盘 this.initTi(); } this.pack(); } catch (Exception e) { e.printStackTrace(); } } // ////////////////////////////////////////////////////////// private TrayIcon ti;// 系统托盘 /** * 配置系统托盘 */ private void initTi() { try { Image image = ImageIO.read(new File(manager.getConfigMap().get(IMG_SYSTEM_STATUSBAR))); PopupMenu popupTi = new PopupMenu();// 弹出菜单 MenuItem ishomeItem = new MenuItem(JM.Name);// 菜单项 popupTi.add(ishomeItem); MenuItem logItem = new MenuItem(manager.getConfigMap().get(LANG_MAIN_MENU_LOG_TEXT));// 菜单项 logItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { manager.openFrame(manager.getLogForm()); } }); popupTi.add(logItem); MenuItem showItem = new MenuItem(manager.getConfigMap().get(LANG_MAIN_MENU_SHOW_TEXT));// 菜单项 ActionListener showListener = new ActionListener() { public void actionPerformed(ActionEvent e) { SystemTray.getSystemTray().remove(ti);// 从系统托盘中移出 setState(0);// 取消最小化状态 setVisible(true);// 重新显示窗口 } }; showItem.addActionListener(showListener); popupTi.add(showItem); MenuItem exitItem = new MenuItem(manager.getConfigMap().get(LANG_MAIN_MENU_EXIT_TEXT));// 菜单项 exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeServer(); } }); popupTi.add(exitItem); ti = new TrayIcon(image, JM.Name, popupTi);// 图标,标题,右键弹出菜单 } catch (Exception e) { e.printStackTrace(); } } /** * 运行系统 */ public void runServer() { if (SystemTray.isSupported()) { setVisible(false);// 隐藏窗口 minimizeToTray();// 如果系统支持托盘图标,将窗口放入系统托盘区 } manager.runServer(); setServerStaters(SERVER_STATE_LOGINING); } /** * 设置服务器提示信息 */ public void setServerStaters(int msnFlag){ switch(msnFlag){ case SERVER_STATE_RUN: ti.displayMessage(JM.Name, manager.getConfigMap().get(LANG_MAIN_TRAY_SERVER_RUN_TEXT), TrayIcon.MessageType.INFO); break; case SERVER_STATE_LOGINING: ti.displayMessage(JM.Name, manager.getConfigMap().get(LANG_MAIN_TRAY_SERVER_LOGINING_TEXT), TrayIcon.MessageType.INFO); break; case SERVER_STATE_STOP: ti.displayMessage(JM.Name, manager.getConfigMap().get(LANG_MAIN_TRAY_SERVER_STOP_TEXT), TrayIcon.MessageType.WARNING); break; case SERVER_STATE_FAIL: ti.displayMessage(JM.Name, manager.getConfigMap().get(LANG_MAIN_TRAY_SERVER_FAIL_TEXT), TrayIcon.MessageType.ERROR); break; } } /** * 关闭系统 */ public void closeServer() { this.setVisible(false);// 隐藏窗口 if (ti != null) SystemTray.getSystemTray().remove(ti);// 从系统托盘中移出 this.dispose();// 关闭画面 this.manager.closeServer();// 关闭系统 } /** * 最小化时候的处理 */ public void minimizeToTray() { try { SystemTray.getSystemTray().add(ti);// 在系统托盘区中增加图标 // windowListener.windowIconified(null); } catch (AWTException e) { e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -