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("用户登录");
}
}
最近下载更多
13133117021 LV5
2024年12月26日
zeng1206 LV7
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日
最近浏览更多
13133117021 LV5
2024年12月26日
Reach_hehe LV1
2024年12月6日
qwertasdfgkwuejwjwjw LV1
2024年6月27日
ethan_
2024年5月29日
暂无贡献等级
28128觅北 LV2
2024年5月22日
krispeng LV15
2024年4月15日
woldxy LV12
2024年4月1日
taoshen95 LV16
2024年1月18日
zeng1206 LV7
2023年12月28日
陈小灏 LV18
2023年12月27日

