即时内部聊天程序——注册

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();
				
			}
		});
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值