package Z0929;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Zhuce extends JFrame {
private JLabel usernamejlabal;
private JLabel passwordjlabal;
private JLabel repasswordjlabal;
private JTextField usernameField;
private JPasswordField passwordField;
private JPasswordField repasswordField;
private JButton zhuce;
private JButton fanhui;
public Zhuce() {
setTitle("用户注册");
setSize(440, 340);
setLocationRelativeTo(null);
setDefaultCloseOperation(2);
setResizable(false);
setUndecorated(false);
usernamejlabal = new JLabel("账号");
passwordjlabal = new JLabel("密码");
repasswordjlabal = new JLabel("确认密码");
usernameField = new JTextField();
passwordField = new JPasswordField();
repasswordField = new JPasswordField();
zhuce = new JButton("完成注册");
fanhui =new JButton("返回登录");
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(" "));
jp.add(new JLabel(" "));
jp.add(usernamejlabal);
jp.add(usernameField);
jp.add(new JLabel(" "));
jp.add(new JLabel(" "));
jp.add(passwordjlabal);
jp.add(passwordField);
jp.add(new JLabel(" "));
jp.add(new JLabel(" "));
jp.add(repasswordjlabal);
jp.add(repasswordField);
jp.add(new JLabel(" "));
jp.add(new JLabel(" "));
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout());
jp2.add(zhuce);
jp2.add(fanhui);
add(jp2, BorderLayout.SOUTH);
add(jp);
add(new JLabel(" "),BorderLayout.WEST);
add(new JLabel(" "),BorderLayout.EAST);
setVisible(true);
zhuce.addActionListener(new ActionListener() {
// 检查输入的注册信息是否符合要求
public void actionPerformed(ActionEvent e) {
if (usernameField.getText().trim().length() < 6) {
JOptionPane.showMessageDialog(Zhuce.this, "用户名长度不够");
return;
} else if (passwordField.getText().trim().length() < 6) {
JOptionPane.showMessageDialog(Zhuce.this, " 密码长度不够");
return;
} else if (!passwordField.getText().trim().equals(repasswordField.getText().trim())) {
JOptionPane.showMessageDialog(Zhuce.this, "两次输入的密码不同");
return;
}
// 发送注册信息
// 注册信息1 登录信息 2 聊天信息 3
String message = 1 + " " + usernameField.getText().trim() + " " + passwordField.getText().trim();
MessageIO io = new MessageIO();
io.SendMessage(message);
// 接收注册结果
// 成功 y 失败 n
String jieshou = io.ReceriveMessag();
if (jieshou.equals("y")) {
JOptionPane.showMessageDialog(Zhuce.this, "注册成功");
Zhuce.this.dispose();
new DengLujm();
} else if (jieshou.equals("n")) {
JOptionPane.showMessageDialog(Zhuce.this, "用户名已存在");
return;
}
}
});
fanhui.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Zhuce.this.dispose();
new DengLujm();
}
});
}
}
即时内部聊天程序——注册
最新推荐文章于 2024-09-08 08:27:55 发布