package com.wenqier.chat.client;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Client extends JFrame {
	private JButton jButton1;

	private JButton jButton2;

	private JLabel jLabel1;

	private JLabel jLabel2;

	private JLabel jLabel3;

	private JPanel jPanel;

	private JTextField username;

	private JTextField hostAddress;

	private JTextField port;

	public Client(String name) {
		super(name);

		initComponents(); // initialize UI
	}

	private void initComponents() {
		jPanel = new JPanel();

		jLabel1 = new JLabel();
		jLabel2 = new JLabel();
		jLabel3 = new JLabel();

		username = new JTextField(15);
		hostAddress = new JTextField(15);
		port = new JTextField(15);

		jButton1 = new JButton();
		jButton2 = new JButton();

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setAlwaysOnTop(true);
		this.setResizable(false);

		jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("用户登录"));

		jLabel1.setText("用户名");
		jLabel2.setText("服务器");
		jLabel3.setText("端口号");

		jButton1.setText("登录");
		jButton2.setText("重置");

		jButton1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Client.this.login(e);
			}
		});

		username.setText("changyong");
		hostAddress.setText("127.0.0.1");
		port.setText("5050");

		jPanel.add(jLabel1);
		jPanel.add(username);
		jPanel.add(jLabel2);
		jPanel.add(hostAddress);
		jPanel.add(jLabel3);
		jPanel.add(port);

		jPanel.add(jButton1);
		jPanel.add(jButton2);

		this.getContentPane().add(jPanel);

		this.setSize(250, 300);
		this.setVisible(true);
	}

	private void login(ActionEvent event) {
		String username = this.username.getText();
		String hostAddress = this.hostAddress.getText();
		String port = this.port.getText();

		ClientConnection clientConnection = new ClientConnection(this,
				hostAddress, Integer.parseInt(port), username);

		if (clientConnection.login()) {
			clientConnection.start();
		} else {
			JOptionPane.showMessageDialog(this, "用户名重复或端口号错误!", "错误",
					JOptionPane.ERROR_MESSAGE);
		}
	}

	public static void main(String[] args) {
		new Client("用户登录");
	}

}
最近下载更多
zeng1206  LV5 2023年12月28日
hentai233  LV1 2023年11月17日
vitcheu  LV1 2023年5月27日
Kevin_001  LV6 2022年7月3日
wxh1234567  LV4 2022年6月20日
106sadadwd  LV2 2022年6月18日
haneri  LV1 2022年6月5日
GaaraNi  LV1 2022年4月21日
炸蝎子奥特  LV1 2022年2月12日
shan454  LV3 2022年1月24日
最近浏览更多
krispeng  LV6 4月15日
woldxy  LV12 4月1日
taoshen95  LV14 1月18日
zeng1206  LV5 2023年12月28日
陈小灏  LV14 2023年12月27日
qazqaz54188 2023年12月10日
暂无贡献等级
hentai233  LV1 2023年11月17日
13161895  LV1 2023年7月4日
fuyouou  LV5 2023年6月29日
2017143155  LV12 2023年6月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友