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

📄 serverpanel2.java

📁 create the email in the server
💻 JAVA
字号:
package za.co.halo.SecureCommunications.gui.server;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;

import za.co.halo.SecureCommunications.POP3Server;
import za.co.halo.SecureCommunications.SMTPServer;
import za.co.halo.SecureCommunications.WebServer;
import za.co.halo.SecureCommunications.network.rmi.RMIServer;

/**
* This code was generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* *************************************
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED
* for this machine, so Jigloo or this code cannot be used legally
* for any corporate or commercial purpose.
* *************************************
*/
public class ServerPanel2 extends JPanel
{
	private JPanel serverNamePanel;
	private JPanel singleNamePanel;
	private JPanel rightPanel;
	private JPanel buttonPanel;
	private JPanel portButtonPanel;
	private JPanel editPortPanel;
	private JLabel portLabel;
	private JList serverNameList;
	private JScrollPane scroll;
	private JSplitPane splitPane;
	private JButton startButton;
	private JButton stopButton;
	private JTextField portText;
	private LocalServerManager localServerManager;
	private JButton saveButton;
	private JButton cancelButton;

	public static void main(String args[])
	{
		JFrame frame = new JFrame();
//		frame.getContentPane().add(new ServerPanel2());
		frame.pack();
		frame.setVisible(true);
	}
	
	public ServerPanel2(LocalServerManager servermanager)
	{
		super();
		localServerManager = servermanager;
		initGUI();
	}
	
	private void initGUI()
	{
		try
		{
			setPreferredSize(new Dimension(630,500));
			this.setLayout(null);
			
			JPanel imagePanel = new ImagePanel("images/servers.png","servers");
			imagePanel.setLayout(null);
			imagePanel.setBounds(0,0,625,83);
			this.add(imagePanel);
			splitPane = new JSplitPane();
			//splitPane.setLayout(null);
			splitPane.setBounds(2,100,600,300);
			splitPane.setDividerLocation(320);
			this.add(splitPane);
			buttonPanel = new JPanel();
			buttonPanel.setLayout(null);
			buttonPanel.setBounds(7,410,327,30);
			this.add(buttonPanel);
			
			startButton = new JButton(new StartAction());
			startButton.setText("Start");
			startButton.setBounds(3,3,110,25);
			startButton.setEnabled(false);
			buttonPanel.add(startButton);
			
			stopButton = new JButton(new StopAction());
			stopButton.setText("Stop");
			stopButton.setBounds(120,3,110,25);
			stopButton.setEnabled(false);
			buttonPanel.add(stopButton);
			
			serverNamePanel = new JPanel();
			serverNamePanel.setMinimumSize(new Dimension(320,600));
			serverNamePanel.setLayout(null);
			serverNamePanel.setBounds(0, 0, 320, 294);
				
			serverNameList = new JList(localServerManager.getServers());
			serverNameList.setBackground(new Color(21,118,146));
			serverNameList.setCellRenderer(new ServerCellRenderer());
			serverNameList.setBounds(2,2,250,306);
			serverNameList.setPreferredSize(new java.awt.Dimension(291, 306));

			MouseListener mouseListener = new MouseAdapter() {
			     public void mouseClicked(MouseEvent e) {
			    	if (e.getClickCount() == 2) 
			         {
			            
			           					        
			         } 
			    	 if (e.getClickCount() == 1) 
			         {
			    		   startButton.setEnabled(true);
			    		   stopButton.setEnabled(true);
			    		   
			    		   editPortPanel = new JPanel();
			 			   editPortPanel.setLayout(null);
			 			   editPortPanel.setBounds(320, 5, 250, 315);
			 				
			 			   portLabel = new JLabel("Port");
			 			   portLabel.setBounds(12,12,80,20);
			 			   
			 			   portText = new JTextField();
			 			   Object element = serverNameList.getSelectedValue();
			 			   portText.setText(""+((AbstractServer) element).getPort());
			 			   portText.setBounds(54,12,180,30);
			 			   portText.setEditable(true);
			 			   
			 			   editPortPanel.add(portLabel);
			 			   editPortPanel.add(portText);
			 			   
			 			   portButtonPanel = new JPanel();
			 			   portButtonPanel.setLayout(null);
			 			   portButtonPanel.setBounds(5,230,300,50);
			 			   editPortPanel.add(portButtonPanel);
			 			   
			 			   saveButton = new JButton(new SaveAction());
			 			   saveButton.setText("Save & Close");
			 			   saveButton.setBounds(0,2,120,25);
			 			   portButtonPanel.add(saveButton);
			 			   
			 			   cancelButton = new JButton(new CancelAction());
			 			   cancelButton.setText("Canel");
			 			   cancelButton.setBounds(125,2,100,25);
			 			   portButtonPanel.add(cancelButton);
			 			   
			 			   splitPane.setRightComponent(editPortPanel);
			    	 }
			     }
			 };
			serverNameList.addMouseListener(mouseListener);
			
			scroll = new JScrollPane(serverNameList);
			scroll.setBounds(0, 0, 320, 295);
			serverNamePanel.add(scroll);
			
			splitPane.add(serverNamePanel, JSplitPane.LEFT);
			
			splitPane.add(new CleanPanel(), JSplitPane.RIGHT);
			
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	class ServerCellRenderer implements ListCellRenderer
	{
		public Component getListCellRendererComponent(JList list, Object object, int index, boolean isSelected, boolean arg4) 
		{
			JPanel panel = new JPanel();
			panel.setLayout(new BorderLayout());
			panel.setBackground(new Color(21,118,146));
			if (object instanceof AbstractServer)
			{
				singleNamePanel = new JPanel();
				singleNamePanel.setLayout(new BorderLayout());
				panel.add(new ViewSingleServerNamesPanel((AbstractServer)object, index, isSelected, startButton, stopButton));
			}
			else 
				panel.add(new JLabel("Could not load information"));
			return panel;
		}
	}
	
	class SaveAction extends AbstractAction {
		SaveAction() {
			super("Save record");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle save actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			String port = portText.getText();
			int p = new Integer(port).intValue();
			Object element = serverNameList.getSelectedValue();
			((AbstractServer) element).setPort(p);
			serverNameList.repaint();
			rightPanel = new JPanel();
			rightPanel.setLayout(null);
			rightPanel.setBounds(5,230,300,50);
			splitPane.setRightComponent(rightPanel);
		}

	}
	
   /**
	* CancelAction class
	* Provides the functionality of handling cancel actions.
	*/
	class CancelAction extends AbstractAction {
		CancelAction() {
			super("cancel creation of RMI account");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle cancel actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			rightPanel = new JPanel();
			rightPanel.setLayout(null);
			rightPanel.setBounds(5,230,300,50);
			splitPane.setRightComponent(rightPanel);
		}
	}
	
	/**
	* StartAction class
	* Provides the functionality of handling start actions.
	*/
	class StartAction extends AbstractAction {
		StartAction() {
			super("start server");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle cancel actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			Object element = serverNameList.getSelectedValue();
			((AbstractServer) element).start();
			serverNameList.repaint();
			stopButton.setEnabled(true);
		}
	}
	
	/**
	* CancelAction class
	* Provides the functionality of handling stop server actions.
	*/
	class StopAction extends AbstractAction {
		StopAction() {
			super("stop server");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle cancel actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			Object element = serverNameList.getSelectedValue();
			//String s = ((AbstractServer) element.)
			((AbstractServer) element).stop();
			System.out.println("---IS_STARTED "+((AbstractServer) element).isStarted());
			serverNameList.repaint();
			startButton.setEnabled(true);
		}

	}
}

⌨️ 快捷键说明

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