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

📄 servergui.java

📁 RemoteWAP is a Remote Administration Tool for any Operating System that can support the Java Virtual
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		btnSelectFile.setText("Browse...");		lblSelect.setText("<html><font size='2'>Selected file : </font</html>");		btnViewLog.setText("View");		btnDeleteLog.setText("Delete");		/* Add listeners to the buttons */		btnSelectFile.addActionListener(this);		btnViewLog.addActionListener(this);		btnDeleteLog.addActionListener(this);		/* Set the size of the buttons */		btnSelectFile.setPreferredSize(new java.awt.Dimension(100, 20));		btnViewLog.setPreferredSize(new java.awt.Dimension(80, 20));		btnDeleteLog.setPreferredSize(new java.awt.Dimension(80, 20));		/* Add it all to the Select Pane */		SelectPane.add(lblSelect);		SelectPane.add(txtFile);		SelectPane.add(btnSelectFile);		SelectPane.add(btnDeleteLog);		SelectPane.add(btnViewLog);		SelectPane.setLayout(MainLayout);		/* And then to the Main Log Pane */		LogPanel.setLayout(MainLayout);		LogPanel.add(SelectPane);		LogPanel.add(LogViewer);		return LogPanel;	}	/**	 * This builds the Configure pane	 * 	 * @return JPane Configure pane for the tab frame	 */	private JComponent makeConfig() {		JPanel ConfigPanel = new JPanel(false);		JPanel portPane = new JPanel();		JPanel logPathPane = new JPanel();		JPanel passcodePane = new JPanel();		JLabel lblConfigPort = new JLabel();		JLabel lblConfigLogPath = new JLabel();		JLabel lblConfigPasscode = new JLabel();		TitledBorder portTitle, passTitle;		lblConfigPort				.setText("<html><font size='2'>"						+ "Please enter the port number that you wish the server "						+ "to listen for incoming connections on.<br>"						+ "<center>Example : http:/*localhost:YourPortNumber<br><center></html>");		lblConfigLogPath				.setText("<html><font size='2'>"						+ "<center>This is where you enter the folder location to where the server "						+ "logs will be stored.<br>The folder <b>MUST</b> already exist in the "						+ "application directory</center></font</html>");		lblConfigPasscode				.setText("<html><font size='2'>"						+ "Please enter the passcode that you wish to use when "						+ "logging on to the server with a mobile phone.<br><center></html>");		configPort.setText(String.valueOf(cfg.getPortNumber()));		configLogPath.setText(String.valueOf(cfg.getLogPath()));		configPasscode.setText(String.valueOf(cfg.getPasscode()));		btnUpdate.setText("Update");		btnUpdate.setPreferredSize(new java.awt.Dimension(140, 20));		btnUpdate.addActionListener(this);		/* Set some default values */		portPane.setPreferredSize(new Dimension(550, 115));		logPathPane.setPreferredSize(new Dimension(550, 100));		passcodePane.setPreferredSize(new Dimension(550, 110));		MainLayout.setAlignment(FlowLayout.LEFT);		portPane.setBorder(BorderFactory				.createEtchedBorder(EtchedBorder.LOWERED));		logPathPane.setBorder(BorderFactory				.createEtchedBorder(EtchedBorder.LOWERED));		passcodePane.setBorder(BorderFactory				.createEtchedBorder(EtchedBorder.LOWERED));		mainTitleBorder = BorderFactory.createTitledBorder(LoweredEtched,				"Log Path");		portTitle = BorderFactory.createTitledBorder(LoweredEtched,				"Port Number");		passTitle = BorderFactory.createTitledBorder(LoweredEtched, "Passcode");		passcodePane.setBorder(passTitle);		logPathPane.setBorder(mainTitleBorder);		portPane.setBorder(portTitle);		portPane.add(lblConfigPort);		portPane.add(configPort);		logPathPane.add(lblConfigLogPath);		logPathPane.add(configLogPath);		passcodePane.add(lblConfigPasscode);		passcodePane.add(configPasscode);		ConfigPanel.add(portPane);		ConfigPanel.add(logPathPane);		ConfigPanel.add(passcodePane);		ConfigPanel.add(btnUpdate);		return ConfigPanel;	}	/**	 * This loads the HTML into a JEditor pane and then returns it	 * 	 * @return JPane Help pane for the tab frame	 */	private JComponent makeHelp() {		JScrollPane HTMLVeiwer = new JScrollPane();		MainLayout.setAlignment(FlowLayout.CENTER);		/* Get the HTML file path */		String helpURL = "file:///" + System.getProperty("user.dir")				+ File.separator + "help" + File.separatorChar + "html"				+ File.separatorChar + "index.html";		try {			/* Display the HTML file in the panel */			JEditorPane EditorPane = new JEditorPane(helpURL);			EditorPane.setEditable(false);			EditorPane.setBackground(UIManager.getColor("Panel.background"));			JViewport vp = HTMLVeiwer.getViewport();			vp.add(EditorPane);		} catch (IOException e) {			System.out.println("Error reading the help HTML file");		}		return HTMLVeiwer;	}	/**	 * This does a wee bit of error checking. It see's if the images for the	 * tab frame exist if they don't it displays an error message.	 * 	 * @param path	 *            The path of the image icons	 * @return The image icon	 */	private ImageIcon createImageIcon(String path) {		String userDir = System.getProperty("user.dir") + File.separator;		String base = "file:" + userDir;		File f = new File(base + File.separator + "images");		try {			URL url = new URL(f + File.separator + path);			ImageIcon ServerIcon = new ImageIcon(url);			return ServerIcon;		} catch (MalformedURLException e) {			log.writeLogFile("Error Loading Image " + path + '\n', cfg					.getLogPath());			return null;		}	}	/**	 * Gets the time attribute and returns it	 * 	 * @return The time value	 */	private String getTime() {		String theTime;		TimeFormat = new SimpleDateFormat("hh:mm:ss a");		Date date = new Date();		theTime = TimeFormat.format(date);		return theTime;	}	/**	 * This method is for the action listeners. It acts on the button presses	 * 	 * @param actionevent	 *            The name of the button pressed	 */	public void actionPerformed(ActionEvent actionevent) {		Object obj = actionevent.getSource();		String currentTime = getTime();		File tmpFile;		if (obj == btnStartServer) {			/* Start the server */			server.startServer();			/* Write the status to the status panel & the log file */			writeLog = '[' + currentTime + ']' + " - WAPServer Started \n";			StatusText.append(writeLog);			log.writeLogFile(writeLog, cfg.getLogPath());			/* Change the status label */			lblCurrent.setText("<html><font color='green' size='2'>"					+ "SERVER ONLINE</font></html>");		}		if (obj == btnStopServer) {			server.stopServer();			writeLog = '[' + currentTime + ']' + " - WAPServer Stopped \n";			StatusText.append(writeLog);			log.writeLogFile(writeLog, cfg.getLogPath());			/* Change the status label */			lblCurrent.setText("<html><font color='red' size='2'>"					+ "SERVER OFFLINE</font></html>");		}		if (obj == btnRestartServer) {			server.stopServer();			server.startServer();			writeLog = '[' + currentTime + ']' + " - WAPServer Restarted \n";			StatusText.append(writeLog);			log.writeLogFile(writeLog, cfg.getLogPath());		}		if (obj == btnSelectFile) {			try {				/* Show a file chooser dialog box */				JFileChooser chooser = new JFileChooser();				int result = chooser.showOpenDialog(this);				tmpFile = chooser.getSelectedFile();				SelectedFile = tmpFile.getPath();			} catch (Exception e) {				/* If there is an error, let the user know about it */				writeLog = '[' + currentTime + ']'						+ " - Error when choosing file! \n";				StatusText.append(writeLog);				log.writeLogFile(writeLog, cfg.getLogPath());				JOptionPane.showMessageDialog(this,						"Error when choosing file!", "Error",						JOptionPane.ERROR_MESSAGE);			}			txtFile.setText(SelectedFile);		}		if (obj == btnUpdate) {			boolean updatedLogs = cfg.writeConfig(configPort.getText(),					configLogPath.getText(), configPasscode.getText());			if (updatedLogs) {				writeLog = '[' + currentTime + ']' + " - Settings Updated!\n";				StatusText.append(writeLog);				log.writeLogFile(writeLog, cfg.getLogPath());			} else {				writeLog = '[' + currentTime + ']' + " - Settings Update Failed!\n";				StatusText.append(writeLog);				log.writeLogFile(writeLog, cfg.getLogPath());				JOptionPane.showMessageDialog(this, "Settings Update Failed!", "Error",						JOptionPane.ERROR_MESSAGE);			}		}		try {			if (obj == btnViewLog) {				/* Get the contents of the file */				String fileContent = log.readLogFile(txtFile.getText());				/* If there is none then inform the user and log it */				if (fileContent == "") {					writeLog = '[' + currentTime + ']'							+ " - File View Failed!(" + txtFile.getText()							+ ")\n";					StatusText.append(writeLog);					log.writeLogFile(writeLog, cfg.getLogPath());					JOptionPane.showMessageDialog(this, "File View Failed!",							"Error", JOptionPane.ERROR_MESSAGE);				} else {					/* Else display it */					fileViewer.setText(fileContent);				}				txtFile.setText("");			}			if (obj == btnDeleteLog) {				boolean isSuccessful;				/* Show a confirm box */				String strDelete = " Are you sure you wish to delete this file ?";				/* Check if they pressed YES or not */				int answer = JOptionPane.showConfirmDialog(this, strDelete);				if (answer == JOptionPane.YES_OPTION) {					/* If they did go and delete the file */					LogManager logger = new LogManager();					isSuccessful = logger.deleteLogFile(txtFile.getText());					/* Check if the delete failed inform the user and log it */					if (isSuccessful) {						writeLog = '[' + currentTime + ']' + " - File Deleted("								+ txtFile.getText() + ")\n";						StatusText.append(writeLog);						log.writeLogFile(writeLog, cfg.getLogPath());					} else {						writeLog = '[' + currentTime + ']'								+ " - File Delete Failed!(" + txtFile.getText()								+ ")\n";						StatusText.append(writeLog);						log.writeLogFile(writeLog, cfg.getLogPath());					}				}				txtFile.setText("");			}		} catch (Exception e) {			String strView = "You have not chosen file to view or delete!";			JOptionPane.showMessageDialog(this, strView, "Error",					JOptionPane.ERROR_MESSAGE);		}	}}

⌨️ 快捷键说明

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