⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitorframe.java

📁 一个远程控制的java测试程序源代码.转于网上
💻 JAVA
字号:
/*
 * @(#)MonitorFrame.java 1.00 2005-9-1
 *
 * Copyright 2005 BeanSoft Studio. All rights reserved.
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package studio.beansoft.remotecontrol;

import java.awt.BorderLayout;
import java.awt.Component;
import java.util.Properties;

import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import studio.beansoft.remotecontrol.client.AbstractCommunicationThread;
import studio.beansoft.remotecontrol.client.HttpCommunicationThread;
import studio.beansoft.remotecontrol.client.TcpCommunicationThread;
import studio.beansoft.util.ResLoader;

/**
 * MonitorFrame is used to monitor the server's screen and do mouse, keyboard
 * operations on it.
 * 
 * Chinese documents: 监控窗口用来监视服务器的屏幕并且在上面进行鼠标和键盘操作.
 * 
 * @author BeanSoft
 * @version 1.00 2005-9-8
 */
public class MonitorFrame extends JFrame {
	/** Resources of MonitorFrame */
	ResLoader resLoader = ResLoader
			.getResource("studio.beansoft.remotecontrol.resources.MonitorFrame");

	/** Content pane of this frame */
	private JPanel jContentPane = null;

	/** Pane used to monitor server screen and capture mouse/keyboard events */
	private MonitorPane monitorPane = null;

	/** Thread used to do communication job with server */
	private AbstractCommunicationThread communicationThread = null;

	private JMenuBar jJMenuBar = null;

	private JMenu jMenuFile = null;

	private JMenuItem jMenuItemConnect = null;

	private JMenuItem jMenuItemPause = null;

	private JMenu jMenuConfig = null;

	private JMenuItem jMenuItemConfig = null;

	private JMenu jMenuHelp = null;

	private JMenuItem jMenuItemHelpContents = null;

	private JMenuItem jMenuItemAbout = null;

	public MonitorFrame() {
		initialize();
		
		// Set mnemonic
		parseAndSetMnemonic(jMenuFile);
		parseAndSetMnemonic(jMenuConfig);
		parseAndSetMnemonic(jMenuHelp);
		parseAndSetMnemonic(jMenuItemConnect);
		parseAndSetMnemonic(jMenuItemConfig);
		parseAndSetMnemonic(jMenuItemPause);
		parseAndSetMnemonic(jMenuItemHelpContents);
		parseAndSetMnemonic(jMenuItemAbout);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		String remote_protocol = ConfigurationManager.getConfiguration()
				.getProperty("remote_protocol");

		if ("http".equalsIgnoreCase(remote_protocol)) {
			communicationThread = new HttpCommunicationThread();
		} else if ("tcp".equalsIgnoreCase(remote_protocol)) {
			communicationThread = new TcpCommunicationThread();
		}
	}
	
	/**
	 * Parse button's text to find a mnemonic, it's normally marked with
	 * an '&', eg: "&F" means F shoud be a mnemonic, and the & shoud not
	 * be displayed.
	 * @param component AbstractButton with text
	 * 
	 */
	private void parseAndSetMnemonic(AbstractButton component) {
		String text = component.getText();
		if(text != null && text.indexOf('&') != -1) {
			int index = text.indexOf('&');
			
			// Check whether text is ended with an &
			if(text.length() > index + 1) {
				component.setMnemonic(text.charAt(index + 1));
				component.setText(text.replaceAll("&", ""));
			}
		}
	}

	/**
	 * This method initializes monitorPane
	 * 
	 * @return studio.beansoft.remotecontrol.MonitorPane
	 */
	private MonitorPane getMonitorPane() {
		if (monitorPane == null) {
			monitorPane = new MonitorPane();
		}
		return monitorPane;
	}

	/**
	 * This method initializes jJMenuBar
	 * 
	 * @return javax.swing.JMenuBar
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getJMenuFile());
			jJMenuBar.add(getJMenuConfig());
			jJMenuBar.add(getJMenuHelp());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenu
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getJMenuFile() {
		if (jMenuFile == null) {
			jMenuFile = new JMenu();
			jMenuFile.setText(resLoader.getText("jMenuFile.text"));
			jMenuFile.add(getJMenuItemConnect());
			jMenuFile.add(getJMenuItemPause());
		}
		return jMenuFile;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemConnect() {
		if (jMenuItemConnect == null) {
			jMenuItemConnect = new JMenuItem();
			jMenuItemConnect.setText(resLoader.getText("jMenuItemConnect.text"));
			jMenuItemConnect
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							if (communicationThread != null
									&& !communicationThread.isAlive()) {
								Properties configuration = ConfigurationManager
										.getConfiguration();
								String protocol = configuration
										.getProperty("remote_protocol");
								String url = "http".equalsIgnoreCase(protocol) ? configuration
										.getProperty("remote_url_http")
										: configuration
												.getProperty("remote_url_tcp");

								String msg = resLoader
										.getText(
												"connection_info",
												protocol,
												url);

								JOptionPane.showMessageDialog(
										MonitorFrame.this, msg);

								// Start the communication thread
								communicationThread.setPane(monitorPane);
								communicationThread.setPaused(false);
								communicationThread.start();
							}
						}
					});
		}

		return jMenuItemConnect;
	}

	/**
	 * This method initializes jMenuItem
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemPause() {
		if (jMenuItemPause == null) {
			jMenuItemPause = new JMenuItem();
			jMenuItemPause.setText(resLoader.getText("jMenuItemPause.text"));
			jMenuItemPause
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							if (communicationThread != null) {
								communicationThread
										.setPaused(!communicationThread
												.isPaused());
							}
						}
					});
		}
		return jMenuItemPause;
	}

	/**
	 * This method initializes jMenuConfig
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getJMenuConfig() {
		if (jMenuConfig == null) {
			jMenuConfig = new JMenu();
			jMenuConfig.setText(resLoader.getText("jMenuConfig.text"));
			jMenuConfig.add(getJMenuItemConfig());
		}
		return jMenuConfig;
	}

	/**
	 * This method initializes jMenuItemConfigClient
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemConfig() {
		if (jMenuItemConfig == null) {
			jMenuItemConfig = new JMenuItem();
			jMenuItemConfig.setText(resLoader.getText("jMenuItemConfig.text"));
			jMenuItemConfig
					.addActionListener(new java.awt.event.ActionListener() {   
				public void actionPerformed(java.awt.event.ActionEvent e) {    
					JOptionPane.showMessageDialog(MonitorFrame.this, resLoader.getText("config_how_to_text"));
				}
			
					});
		}
		return jMenuItemConfig;
	}

	/**
	 * This method initializes jMenuHelp
	 * 
	 * @return javax.swing.JMenu
	 */
	private JMenu getJMenuHelp() {
		if (jMenuHelp == null) {
			jMenuHelp = new JMenu();
			jMenuHelp.setText(resLoader.getText("jMenuHelp.text"));
			jMenuHelp.add(getJMenuItemHelpContents());
			jMenuHelp.addSeparator();
			jMenuHelp.add(getJMenuItemAbout());
		}
		return jMenuHelp;
	}

	/**
	 * This method initializes jMenuItemHelpContent
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemHelpContents() {
		if (jMenuItemHelpContents == null) {
			jMenuItemHelpContents = new JMenuItem();
			jMenuItemHelpContents.setText(resLoader.getText("jMenuItemHelpContents.text"));
			jMenuItemHelpContents
					.addActionListener(new java.awt.event.ActionListener() {   
				public void actionPerformed(java.awt.event.ActionEvent e) {    
					JOptionPane.showMessageDialog(MonitorFrame.this, resLoader.getText("Help_Contents"));
				}
			
					});
		}
		return jMenuItemHelpContents;
	}

	/**
	 * This method initializes jMenuItemAbout
	 * 
	 * @return javax.swing.JMenuItem
	 */
	private JMenuItem getJMenuItemAbout() {
		if (jMenuItemAbout == null) {
			jMenuItemAbout = new JMenuItem();
			jMenuItemAbout.setText(resLoader.getText("jMenuItemAbout.text"));
			jMenuItemAbout
					.addActionListener(new java.awt.event.ActionListener() {   
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JOptionPane.showMessageDialog(MonitorFrame.this, resLoader.getText("About_Info"));
				}
			
					});
		}
		return jMenuItemAbout;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// Set look and feel to system style
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			// TODO: handle exception
		}

		MonitorFrame frame = new MonitorFrame();
		frame.setVisible(true);
	}

	/**
	 * This method initializes this frame
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(850, 700);
		this.setJMenuBar(getJJMenuBar());
		this.getContentPane().add(new JScrollPane(getJContentPane()));
		this.setTitle(resLoader.getText("Frame.title"));
		// this.setUndecorated(true);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getMonitorPane(), java.awt.BorderLayout.CENTER);
		}
		return jContentPane;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -