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

📄 updateuserinfoface.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;

class UpdateUserInfoFace 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();

    private int userId = 0;

    public UpdateUserInfoFace() {
        super("修改用户信息");
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public UpdateUserInfoFace(int userId) {
        super("修改用户信息");
        this.userId = userId;
        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) {
        ((UserInfo) Client.localUser.get(userId)).setInfoType(3); //设置类型为修改用户信息请求
        ((UserInfo) Client.localUser.get(userId)).setOnLine(false); //设置在线状态为false,用以判断更新信息是否成功
        //判断两次输入的密码是否相同
        if (String.valueOf(this.password.getPassword()).equals(String.
                valueOf(this.password2.getPassword()))) {
            ((UserInfo) Client.localUser.get(userId)).setUserName(String.
                    valueOf(this.username.getText()));
            ((UserInfo) Client.localUser.get(userId)).setPassWord(String.
                    valueOf(this.password.getPassword()));
            Client client = new Client();
            client.send(((UserInfo) Client.localUser.get(userId)));//向服务器提交修改用户信息请求
            this.dispose();
        } else {//两次输入的密码不同要求用户重新输入
            JOptionPane.showMessageDialog(null, "您两次输入的密码不相同,请重新输入!");
            this.password.setText("");
            this.password2.setText("");
        }
    }

    //取消按钮事件
    public void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();
    }
}

⌨️ 快捷键说明

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