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

📄 logindialog.java~52~

📁 Java 聊天程序 有客户端和服务端。
💻 JAVA~52~
📖 第 1 页 / 共 3 页
字号:
package chatclient;

import java.io.*;
import java.net.*;
import java.util.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import com.borland.jbcl.layout.*;

/**
 * <p>Title: 聊天系统客户端</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: 个人</p>
 * @author Mothz
 * @version 1.0
 */

public class LoginDialog
    extends JDialog {
    JPanel panel1 = new JPanel();
    XYLayout xYLayout2 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JButton jButton1 = new JButton();
    JPasswordField userPassword = new JPasswordField();
    JLabel jLabel2 = new JLabel();
    JTextField userID = new JTextField();
    //构造方法
    public LoginDialog(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            pack();
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public LoginDialog() {
        this(new Frame(), "用户登录", false);
    }

    private void jbInit() throws Exception {
        Toolkit.getDefaultToolkit().createImage("images/chat2.png");
        panel1.setLayout(xYLayout2);
        this.getContentPane().setLayout(cardLayout1);
        jLabel1.setText("帐号:");
        jButton1.setBorder(null);
        jButton1.setIcon(new ImageIcon("images/enter.jpg"));
        jButton1.addActionListener(new LoginDialog_jButton1_actionAdapter(this));
        userPassword.setColumns(10);
        jLabel2.setText("密码:");
        userID.setColumns(20);
        //限制用户只能输入数字
        userID.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent event) {
                char ch = event.getKeyChar();
                if (ch < '0' || ch > '9') {
                    event.consume();
                }
            }
        });
        jButton2.setBorder(null);
        jButton2.setIcon(new ImageIcon("images/cancel.jpg"));
        jButton2.addActionListener(new LoginDialog_jButton2_actionAdapter(this));
        jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel4.setIcon(new ImageIcon("images/loginfrist.gif"));
        jLabel4.addMouseListener(new LoginDialog_jLabel4_mouseAdapter(this));
        jLabel4.setCursor(Cursor.getDefaultCursor());
        rege.setLayout(null);
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(14, 7, 290, 38));
        jPanel1.setLayout(borderLayout1);
        jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
        jLabel3.setForeground(Color.blue);
        jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel3.setText("新用户注册");
        jPanel3.setBorder(BorderFactory.createEtchedBorder());
        jPanel3.setBounds(new Rectangle(14, 47, 288, 152));
        jPanel3.setLayout(null);
        jLabel6.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel6.setText("新密码:");
        jLabel6.setBounds(new Rectangle(30, 7, 42, 15));
        jLabel7.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel7.setText("确认密码:");
        jLabel7.setBounds(new Rectangle(14, 35, 58, 15));
        jLabel8.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel8.setText("密码保护:");
        jLabel8.setBounds(new Rectangle(13, 62, 59, 15));
        Password1.setBounds(new Rectangle(80, 6, 169, 20));
        PasswordA.setBounds(new Rectangle(80, 61, 169, 20));
        Password2.setBounds(new Rectangle(80, 33, 169, 20));
        jButton3.setBounds(new Rectangle(39, 114, 75, 20));
        jButton3.setBorder(null);
        jButton3.setIcon(new ImageIcon("images/zhuce.jpg"));
        jButton3.addActionListener(new LoginDialog_jButton3_actionAdapter(this));
        jButton4.setBounds(new Rectangle(159, 114, 75, 20));
        jButton4.setBorder(null);
        jButton4.setIcon(new ImageIcon("images/cancel.jpg"));
        jButton4.addActionListener(new LoginDialog_jButton4_actionAdapter(this));
        jLabel9.setForeground(Color.blue);
        jLabel9.setText("<html><u>号码注册</u></html>");
        jLabel9.addMouseListener(new LoginDialog_jLabel9_mouseAdapter(this));
        jLabel9.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        jLabel10.setForeground(Color.blue);
        jLabel10.setText("<html><u>密码重设</u></html>");
        jLabel10.addMouseListener(new LoginDialog_jLabel10_mouseAdapter(this));
        jLabel10.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        forget.setLayout(null);
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setBounds(new Rectangle(14, 7, 290, 38));
        jPanel2.setLayout(borderLayout2);
        jLabel11.setFont(new java.awt.Font("宋体", Font.BOLD, 18));
        jLabel11.setForeground(Color.blue);
        jLabel11.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel11.setText("密码重设");
        jPanel4.setBorder(BorderFactory.createEtchedBorder());
        jPanel4.setBounds(new Rectangle(14, 47, 290, 151));
        jPanel4.setLayout(null);
        jLabel12.setText("帐号:");
        jLabel12.setBounds(new Rectangle(47, 6, 33, 15));
        jLabel13.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel13.setText("密码保护:");
        jLabel13.setBounds(new Rectangle(17, 31, 63, 15));
        jLabel14.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel14.setText("新密码:");
        jLabel14.setBounds(new Rectangle(32, 57, 48, 15));
        jLabel15.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel15.setText("确认密码:");
        jLabel15.setBounds(new Rectangle(24, 85, 56, 15));
        forgetNumber.setBounds(new Rectangle(84, 3, 165, 20));
        forgetNumber.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent event) {
                char ch = event.getKeyChar();
                if (ch < '0' || ch > '9') {
                    event.consume();
                }
            }
        });

        forgetPasswordA.setBounds(new Rectangle(84, 29, 165, 20));
        forgetPassword1.setBounds(new Rectangle(84, 56, 165, 20));
        forgetPassword2.setBounds(new Rectangle(84, 82, 165, 20));
        jButton5.setBounds(new Rectangle(47, 114, 75, 20));
        jButton5.setBorder(null);
        jButton5.setIcon(new ImageIcon("images/sureamend.jpg"));
        jButton5.addActionListener(new LoginDialog_jButton5_actionAdapter(this));
        jButton6.setBounds(new Rectangle(164, 114, 75, 20));
        jButton6.setBorder(null);
        jButton6.setIcon(new ImageIcon("images/cancel.jpg"));
        jButton6.addActionListener(new LoginDialog_jButton6_actionAdapter(this));
        jLabel16.setForeground(Color.red);
        jLabel16.setText("*");
        jLabel16.setBounds(new Rectangle(253, 7, 17, 15));
        jLabel17.setForeground(Color.red);
        jLabel17.setText("*");
        jLabel17.setBounds(new Rectangle(253, 35, 17, 15));
        jLabel18.setForeground(Color.red);
        jLabel18.setText("*");
        jLabel18.setBounds(new Rectangle(253, 62, 17, 15));
        jLabel19.setForeground(Color.red);
        jLabel19.setText("注:密码保护注册成功后不可更改");
        jLabel19.setBounds(new Rectangle(60, 87, 186, 15));
        jPanel5.setLayout(null);
        jPanel5.setVisible(false);
        jPanel6.setBorder(BorderFactory.createEtchedBorder());
        jPanel6.setBounds(new Rectangle(14, 7, 288, 36));
        jLabel20.setFont(new java.awt.Font("宋体", Font.PLAIN, 14));
        jLabel20.setForeground(Color.blue);
        jLabel20.setText("用户密码修改");
        jPanel7.setBorder(BorderFactory.createEtchedBorder());
        jPanel7.setBounds(new Rectangle(14, 47, 288, 152));
        jPanel7.setLayout(null);
        jLabel21.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel21.setText("帐号:");
        jLabel21.setBounds(new Rectangle(27, 9, 48, 15));
        jTextField1.setBounds(new Rectangle(82, 7, 171, 20));
        jTextField1.addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent event) {
                char ch = event.getKeyChar();
                if (ch < '0' || ch > '9') {
                    event.consume();
                }
            }
        });

        jLabel22.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel22.setText("旧密码:");
        jLabel22.setBounds(new Rectangle(28, 33, 47, 15));
        jPasswordField1.setBounds(new Rectangle(82, 32, 171, 20));
        jLabel23.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel23.setText("新密码:");
        jLabel23.setBounds(new Rectangle(27, 62, 48, 15));
        jPasswordField2.setBounds(new Rectangle(82, 59, 171, 20));
        jLabel24.setHorizontalAlignment(SwingConstants.RIGHT);
        jLabel24.setText("确认密码:");
        jLabel24.setBounds(new Rectangle(21, 87, 54, 15));
        jPasswordField3.setBounds(new Rectangle(82, 86, 171, 20));
        jButton7.setBounds(new Rectangle(50, 115, 75, 20));
        jButton7.setBorder(null);
        jButton7.setIcon(new ImageIcon("images/sureamend.jpg"));
        jButton7.addActionListener(new LoginDialog_jButton7_actionAdapter(this));
        jButton8.setBounds(new Rectangle(166, 115, 75, 20));
        jButton8.setBorder(null);
        jButton8.setIcon(new ImageIcon("images/cancel.jpg"));
        jButton8.addActionListener(new LoginDialog_jButton8_actionAdapter(this));
        jLabel25.setForeground(Color.blue);
        jLabel25.setText("<html><u>密码修改</u></html>");
        jLabel25.addMouseListener(new LoginDialog_jLabel25_mouseAdapter(this));
        jLabel25.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        panel1.add(jLabel1, new XYConstraints(38, 81, -1, -1));
        panel1.add(jLabel2, new XYConstraints(38, 115, -1, -1));
        panel1.add(jLabel5, new XYConstraints(115, 190, 52, 14));
        panel1.add(jLabel4, new XYConstraints(20, 7, 301, 61));
        panel1.add(userPassword, new XYConstraints(79, 109, 156, 20));
        panel1.add(userID, new XYConstraints(79, 79, 156, -1));
        panel1.add(jLabel9, new XYConstraints(244, 72, 56, 18));
        rege.add(jPanel1);
        jPanel1.add(jLabel3, java.awt.BorderLayout.CENTER);
        rege.add(jPanel3);
        jPanel3.add(Password1);
        jPanel3.add(Password2);
        jPanel3.add(jLabel7);
        jPanel3.add(PasswordA);
        jPanel3.add(jLabel8);
        jPanel3.add(jLabel6);
        jPanel3.add(jLabel16);
        jPanel3.add(jLabel17);
        jPanel3.add(jLabel18);
        jPanel3.add(jButton4);
        jPanel3.add(jButton3);
        jPanel3.add(jLabel19);
        this.getContentPane().add(forget, "forget");
        jPanel4.add(jLabel12);
        jPanel4.add(forgetNumber);
        jPanel4.add(forgetPasswordA);
        jPanel4.add(forgetPassword1);
        jPanel4.add(forgetPassword2);
        jPanel4.add(jLabel13);
        jPanel4.add(jLabel14);
        jPanel4.add(jLabel15);
        jPanel4.add(jButton6);
        jPanel4.add(jButton5);
        this.getContentPane().add(panel1, "panel1");
        forget.add(jPanel2);
        jPanel2.add(jLabel11, java.awt.BorderLayout.CENTER);
        forget.add(jPanel4);
        this.getContentPane().add(jPanel5, "jPanel5");
        jPanel5.add(jPanel6);
        jPanel5.add(jPanel7);
        jPanel7.add(jLabel21);
        jPanel7.add(jTextField1);
        jPanel7.add(jPasswordField1);
        jPanel7.add(jLabel22);
        jPanel7.add(jLabel23);
        jPanel7.add(jPasswordField2);
        jPanel7.add(jPasswordField3);
        jPanel7.add(jLabel24);
        jPanel7.add(jButton7);
        jPanel7.add(jButton8);
        this.getContentPane().add(rege, "rege");
        jPanel6.add(jLabel20);
        panel1.add(jLabel25, new XYConstraints(244, 115, -1, 18));
        panel1.add(jLabel10, new XYConstraints(244, 94, -1, 18));
        panel1.add(jButton2, new XYConstraints(176, 157, -1, 20));
        panel1.add(jButton1, new XYConstraints(60, 157, -1, 20));
        rege.setVisible(false);
        panel1.setVisible(true);
        forget.setVisible(false);
    }

    //定义数据流和网络变量
    Socket socket = null; //定义连接套接字
    //用来实现客户端接受服务器的数据的输入流
    DataInputStream dis = null;
    //用来实现客户端向服务器的输出流
    DataOutputStream dos = null;
    Listen listen = null; //定义客户端线程

    int count = 0;
    String name = null;
    JButton jButton2 = new JButton();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    CardLayout cardLayout1 = new CardLayout();
    JPanel rege = new JPanel();
    JPanel forget = new JPanel();
    JLabel jLabel3 = new JLabel();
    JPanel jPanel1 = new JPanel();
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel3 = new JPanel();
    JLabel jLabel6 = new JLabel();
    JLabel jLabel7 = new JLabel();
    JLabel jLabel8 = new JLabel();
    JPasswordField Password1 = new JPasswordField();
    JTextField PasswordA = new JTextField();
    JPasswordField Password2 = new JPasswordField();
    JButton jButton3 = new JButton();
    JButton jButton4 = new JButton();
    JLabel jLabel9 = new JLabel();
    JLabel jLabel10 = new JLabel();
    JPanel jPanel2 = new JPanel();
    BorderLayout borderLayout2 = new BorderLayout();
    JLabel jLabel11 = new JLabel();
    JPanel jPanel4 = new JPanel();
    JLabel jLabel12 = new JLabel();
    JLabel jLabel13 = new JLabel();
    JLabel jLabel14 = new JLabel();
    JLabel jLabel15 = new JLabel();
    JTextField forgetNumber = new JTextField();
    JTextField forgetPasswordA = new JTextField();
    JPasswordField forgetPassword1 = new JPasswordField();
    JPasswordField forgetPassword2 = new JPasswordField();
    JButton jButton5 = new JButton();
    JButton jButton6 = new JButton();
    JLabel jLabel16 = new JLabel();
    JLabel jLabel17 = new JLabel();
    JLabel jLabel18 = new JLabel();
    JLabel jLabel19 = new JLabel();
    JPanel jPanel5 = new JPanel();
    JPanel jPanel6 = new JPanel();
    JLabel jLabel20 = new JLabel();
    JPanel jPanel7 = new JPanel();
    JLabel jLabel21 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel22 = new JLabel();
    JPasswordField jPasswordField1 = new JPasswordField();
    JLabel jLabel23 = new JLabel();
    JPasswordField jPasswordField2 = new JPasswordField();
    JLabel jLabel24 = new JLabel();
    JPasswordField jPasswordField3 = new JPasswordField();
    JButton jButton7 = new JButton();
    JButton jButton8 = new JButton();
    JLabel jLabel25 = new JLabel();

    //断开连接
    public void disconnect() {
        if (socket != null) {
            try {
                send("QUIT:" + name);
                socket.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            finally {
                listen.stop();

⌨️ 快捷键说明

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