⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registerface.java

📁 JAVA的聊天源代码
💻 JAVA
字号:
package qq;

import javax.swing.JFrame;
import javax.swing.JLabel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.net.InetAddress;
import java.net.UnknownHostException;

class RegisterFace extends JFrame {
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JTextField username = new JTextField();
    JPasswordField password = new JPasswordField();
    JPasswordField password2 = new JPasswordField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();

    public RegisterFace() {
        super("用户注册");
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(xYLayout1);
        jLabel1.setFont(new java.awt.Font("黑体", Font.PLAIN, 16));
        jLabel1.setText("用户昵称");
        username.setToolTipText("请输入用户昵称");
        password.setToolTipText("请输入注册密码");
        password2.setToolTipText("请确认注册密码");
        jButton2.setText("重置");
        jButton2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jButton2_actionPerformed(e);
            }
        });
        jButton1.setText("注册");
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jButton1_actionPerformed(e);
            }
        });
        jLabel3.setFont(new java.awt.Font("黑体", Font.PLAIN, 16));
        jLabel3.setText("确认密码");
        jLabel2.setFont(new java.awt.Font("黑体", Font.PLAIN, 16));
        this.setResizable(false);
        this.setVisible(true);
        this.getContentPane().add(password2,
                                  new XYConstraints(177, 162, 134, 34));
        xYLayout1.setWidth(388);
        xYLayout1.setHeight(300);
        this.getContentPane().add(jButton1, new XYConstraints(73, 223, 84, 35));
        this.getContentPane().add(password, new XYConstraints(177, 109, 134, 34));
        this.getContentPane().add(username, new XYConstraints(177, 57, 134, 34));
        this.getContentPane().add(jLabel2, new XYConstraints(62, 109, 85, 30));
        this.getContentPane().add(jLabel1, new XYConstraints(62, 57, 85, 30));
        this.getContentPane().add(jLabel3, new XYConstraints(62, 162, 85, 30));
        jLabel2.setText("登陆密码");
        this.getContentPane().add(jButton2, new XYConstraints(204, 223, 84, 35));

        this.setLocation(400, 130);
        this.pack();
    }

    //注册按钮事件
    public void jButton1_actionPerformed(ActionEvent e) {

        Client client = new Client();
        client.userInfo.setInfoType(2);
        client.userInfo.setUserId(0);
        client.userInfo.setPassWord(String.valueOf(this.password.getPassword()));
        client.userInfo.setUserName(this.username.getText());
        String[] ip = null;
        try {
            ip = String.valueOf(InetAddress.getLocalHost()).split("/", 2);
        } catch (UnknownHostException ex) {
        }
        client.userInfo.setUserIp(ip[1]);
        client.userInfo.setUserPort(client.userPort);
        client.userInfo.setOnLine(false);

        if (String.valueOf(this.password.getPassword()).equals(String.
                valueOf(this.password2.getPassword()))) {
            client.send(client.userInfo);
            client.userInfo = (UserInfo) client.get(client.userInfo.getUserPort());
            JOptionPane.showMessageDialog(null,
                                          "您的QQ号码为:" +
                                          String.valueOf(client.userInfo.
                    getUserId()));
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(null, "您两次输入的密码不相同,请重新输入!");
            this.password.setText("");
            this.password2.setText("");
        }
    }

    //重置按钮事件
    public void jButton2_actionPerformed(ActionEvent e) {
        this.username.setText("");
        this.password.setText("");
        this.password2.setText("");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -