【java swing 编程】文件替换小秘书(三)

服务器登录信息界面的实现代码如下:

package panel;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class FTPServerPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	
	private JTextField hostName1 = null;
	private JTextField hostName2 = null;
	private JTextField hostName3 = null;
	private JTextField hostName4 = null;
	private JTextField port = null;
	private JTextField userName = null;
	private JPasswordField password = null;
	
	public FTPServerPanel() {
		super();
		setLayout(new GridLayout(2,1));
		
		//创建基本信息的面板
		JPanel basicInfoPanel = new JPanel();
		basicInfoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "基本信息"));
		basicInfoPanel.setLayout(new GridLayout(5, 1));
		
		basicInfoPanel.add(new JLabel());
		JPanel hostPanel = new JPanel();
		hostPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		hostPanel.add(new JLabel("  主机地址(*):"));
		hostName1 = new JTextField(3);
		hostName1.addKeyListener(new KeyAdapter() {

			@Override
			public void keyTyped(KeyEvent e) {
				int keyChar = e.getKeyChar();
				if(!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
					e.setKeyChar('\0');
				}
			}
		});
		hostPanel.add(hostName1);
		hostPanel.add(new JLabel("."));
		hostName2 = new JTextField(3);
		hostName2.addKeyListener(new KeyAdapter() {

			@Override
			public void keyTyped(KeyEvent e) {
				
				int keyChar = e.getKeyChar();
				if(!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
					e.setKeyChar('\0');
				}
			}
		});
		hostPanel.add(hostName2);
		hostPanel.add(new JLabel("."));
		hostName3 = new JTextField(3);
		hostName3.addKeyListener(new KeyAdapter() {

			@Override
			public void keyTyped(KeyEvent e) {
				
				int keyChar = e.getKeyChar();
				if(!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
					e.setKeyChar('\0');
				}
			}
		});
		hostPanel.add(hostName3);
		hostPanel.add(new JLabel("."));
		hostName4 = new JTextField(3);
		hostName4.addKeyListener(new KeyAdapter() {

			@Override
			public void keyTyped(KeyEvent e) {
				
				int keyChar = e.getKeyChar();
				if(!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
					e.setKeyChar('\0');
				}
			}
		});
		hostPanel.add(hostName4);
		
		hostPanel.add(new JLabel("          端口(*):"));
		port = new JTextField(10);
		port.addKeyListener(new KeyAdapter() {

			@Override
			public void keyTyped(KeyEvent e) {
				int keyChar = e.getKeyChar();
				if(!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
					e.setKeyChar('\0');
				}
			}
		});
		hostPanel.add(port);
		basicInfoPanel.add(hostPanel);
		
		JPanel userPanel = new JPanel();
		userPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		userPanel.add(new JLabel("  用户名(*):    "));
		userName = new JTextField(17);
		userPanel.add(userName);
		basicInfoPanel.add(userPanel);
		
		JPanel passwordPanel = new JPanel();
		passwordPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		passwordPanel.add(new JLabel("  密码:                   "));
		password = new JPasswordField(17);
		passwordPanel.add(password);
		basicInfoPanel.add(passwordPanel);
		
		add(basicInfoPanel);
		
		//创建备注信息的面板
		JPanel backInfoPanel = new JPanel();
		backInfoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "备注信息"));
		backInfoPanel.setLayout(new GridLayout(6, 1));
		
		backInfoPanel.add(new JLabel("   1、请注意主机地址、端口、用户名是必填项。"));
		backInfoPanel.add(new JLabel("   2、主机地址是IP,即:192.168.11.200的形式;而端口则只能输入数字。"));
		backInfoPanel.add(new JLabel("   3、亲,路径配置只针对服务器上同一个用户,针对多个用户可拷贝并运行多个该工具进行重新配置。"));
		backInfoPanel.add(new JLabel("   4、路径配置必须是目录层级,即:文件夹。不能设定成具体的文件,否则无效;服务器路径务必以“/”开头。"));
		backInfoPanel.add(new JLabel("   5、该工具提供配置信息保存、文件替换和文件下载的功能,操作时请确认各配置项的正确性。"));
		add(backInfoPanel);
	}
	
	public JTextField getHostName1() {
		return hostName1;
	}


	public void setHostName1(JTextField hostName1) {
		this.hostName1 = hostName1;
	}


	public JTextField getHostName2() {
		return hostName2;
	}


	public void setHostName2(JTextField hostName2) {
		this.hostName2 = hostName2;
	}


	public JTextField getHostName3() {
		return hostName3;
	}


	public void setHostName3(JTextField hostName3) {
		this.hostName3 = hostName3;
	}


	public JTextField getHostName4() {
		return hostName4;
	}


	public void setHostName4(JTextField hostName4) {
		this.hostName4 = hostName4;
	}


	public JTextField getPort() {
		return port;
	}

	public void setPort(JTextField port) {
		this.port = port;
	}

	public JTextField getUserName() {
		return userName;
	}

	public void setUserName(JTextField userName) {
		this.userName = userName;
	}

	public JPasswordField getPassword() {
		return password;
	}

	public void setPassword(JPasswordField password) {
		this.password = password;
	}
}


 

你可能感兴趣的:(java,java,ftp,Swing编程,awt编程)