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

📄 logintest.java~63~

📁 Tt s a good book ,if you want to learn java good
💻 JAVA~63~
字号:
package sos;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.Rectangle;
import java.awt.Font;
import javax.swing.border.TitledBorder;

public class LogInTest extends JDialog {
    public String[] user_Student = {"ykyk"};
    public String[] user_Teacher = {"teacherteacher"};
    public static String warning = "注意!用户名或密码错误!请重新输入。";
    public static String name;
    public LogInTest(JFrame frame, boolean modal) {
        super(frame, modal);
        setTitle("登录系统");
        setSize(418, 350);
        setResizable(false);
        try {
            jbInit();
        } catch (Exception ex) {
            dispose();
        }
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        setLocation((screenSize.width - frameSize.width) / 2,
                    (screenSize.height - frameSize.height) / 2 + 105);

        setVisible(true);

    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        label_wel.setFont(new java.awt.Font("隶书", Font.BOLD | Font.ITALIC, 40));
        label_wel.setForeground(SystemColor.textHighlight);
        label_wel.setHorizontalAlignment(SwingConstants.CENTER);
        label_wel.setHorizontalTextPosition(SwingConstants.CENTER);
        label_wel.setText("登录系统:");
        label_wel.setBounds(new Rectangle(32, 0, 338, 61));
        label_cat.setFont(new java.awt.Font("黑体", Font.BOLD, 20));
        label_cat.setText("登录身份:");
        label_cat.setBounds(new Rectangle(60, 67, 120, 34));
        label_ID.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
        label_ID.setText("用户姓名:");
        label_ID.setBounds(new Rectangle(60, 105, 120, 34));
        label_pwd.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
        label_pwd.setText("登录密码:");
        label_pwd.setBounds(new Rectangle(60, 148, 120, 34));
        this.getContentPane().setBackground(SystemColor.text);
        button_Reset.setBounds(new Rectangle(142, 199, 121, 37));
        button_Reset.setFont(new java.awt.Font("华文彩云", Font.BOLD | Font.ITALIC,
                                               20));
        button_Reset.setText("重置");
        button_Reset.addActionListener(new LogIn_button_Reset_actionAdapter(this));
        button_Confirm.setBounds(new Rectangle(15, 199, 121, 37));
        button_Confirm.setFont(new java.awt.Font("华文彩云",
                                                 Font.BOLD | Font.ITALIC, 20));
        button_Confirm.setText("登录");
        button_Confirm.addActionListener(new LogIn_button_Confirm_actionAdapter(this));
        tf_ID.setFont(new java.awt.Font("Times New Roman",
                                        Font.BOLD | Font.ITALIC, 20));
        tf_ID.setBounds(new Rectangle(193, 104, 155, 35));
        tf_ID.addMouseListener(new LogInTest_tf_ID_mouseAdapter(this));
        tf_ID.addActionListener(new LogInTest_tf_ID_actionAdapter(this));
        pf_ID.setFont(new java.awt.Font("Dialog", Font.BOLD, 20));
        pf_ID.setBounds(new Rectangle(193, 147, 155, 35));
        pf_ID.addMouseListener(new LogInTest_pf_ID_mouseAdapter(this));
        pf_ID.addActionListener(new LogIn_pf_ID_actionAdapter(this));

        jRadioButton1.setBackground(Color.green);
        jRadioButton1.setBorder(titledBorder2);
        jRadioButton1.setText("学生");
        jRadioButton1.setOpaque(false);
        jRadioButton1.setBounds(new Rectangle(195, 67, 66, 25));
        jRadioButton1.addActionListener(new LogIn_jRadioButton1_actionAdapter(this));
        jRadioButton2.setBackground(Color.white);
        jRadioButton2.setBorder(titledBorder1);
        jRadioButton2.setText("教师");
        jRadioButton2.setOpaque(false);
        jRadioButton2.setBounds(new Rectangle(257, 67, 66, 25));
        jRadioButton2.addActionListener(new LogIn_jRadioButton2_actionAdapter(this));
        jButton_Cancel.setBounds(new Rectangle(269, 199, 121, 37));
        jButton_Cancel.setFont(new java.awt.Font("华文彩云",
                                                 Font.BOLD | Font.ITALIC, 20));
        jButton_Cancel.setText("退出");
        jButton_Cancel.addActionListener(new
                                         LogInTest_jButton_Cancel_actionAdapter(this));
        jLabel_Warning.setFont(new java.awt.Font("华文新魏", Font.BOLD, 20));
        jLabel_Warning.setForeground(Color.red);
        jLabel_Warning.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel_Warning.setText("");
        jLabel_Warning.setBounds(new Rectangle(10, 241, 382, 52));
        this.getContentPane().add(label_wel);
        this.getContentPane().add(label_ID);
        this.getContentPane().add(label_pwd);
        this.getContentPane().add(tf_ID);
        this.getContentPane().add(pf_ID);
        this.getContentPane().add(label_cat);
        this.getContentPane().add(jRadioButton1);
        this.getContentPane().add(jRadioButton2);
        this.getContentPane().add(jLabel_Warning);
        this.getContentPane().add(button_Confirm);
        this.getContentPane().add(button_Reset);
        this.getContentPane().add(jButton_Cancel);

    }

    JLabel label_wel = new JLabel();
    JLabel label_cat = new JLabel();
    JLabel label_ID = new JLabel();
    JLabel label_pwd = new JLabel();
    JButton button_Reset = new JButton();
    JButton button_Confirm = new JButton();
    JTextField tf_ID = new JTextField();
    JPasswordField pf_ID = new JPasswordField();
    JRadioButton jRadioButton1 = new JRadioButton("", true);
    JRadioButton jRadioButton2 = new JRadioButton("", false);
    JButton jButton_Cancel = new JButton();
    JLabel jLabel_Warning = new JLabel();
    TitledBorder titledBorder1 = new TitledBorder("");
    TitledBorder titledBorder2 = new TitledBorder("");
    public void button_Confirm_actionPerformed(ActionEvent e) {
        checkPassword();
        if (TestFrame.hasLogIn == true) {
            dispose();
            TestFrame.reset();
        }
    }

    public void jRadioButton1_actionPerformed(ActionEvent e) {
        jRadioButton2.setSelected(false);
        TestFrame.id = 0;
    }

    public void jRadioButton2_actionPerformed(ActionEvent e) {
        jRadioButton1.setSelected(false);
        TestFrame.id = 1;
    }

    public void pf_ID_actionPerformed(ActionEvent e) {
        checkPassword();
        if (TestFrame.hasLogIn == true) {
            dispose();
            TestFrame.reset();
        }
    }

    public void button_Reset_actionPerformed(ActionEvent e) {
        tf_ID.setText("");
        pf_ID.setText("");
        jLabel_Warning.setText("");
    }

    public void tf_ID_actionPerformed(ActionEvent e) {
        checkPassword();
        if (TestFrame.hasLogIn == true) {
            dispose();
            TestFrame.reset();
        }
    }

    public void checkPassword() {
        try {
            name = tf_ID.getText();
            String currentUser = tf_ID.getText().trim() +
                                 pf_ID.getText().trim();
            // System.out.println(currentUser);///////////test
            for (int i = 0; i < user_Student.length && TestFrame.id == 0; i++) {
                if (currentUser.equals(user_Student[i])) {
                    TestFrame.hasLogIn = true;
                    TestFrame.jLabel_Wel.setText(name + "同学,你好!");
                    break;
                } else {
                    jLabel_Warning.setText(warning);
                }
            }
            for (int i = 0; i < user_Teacher.length && TestFrame.id == 1; i++) {
                if (currentUser.equals(user_Teacher[i])) {
                    TestFrame.hasLogIn = true;
                    TestFrame.jLabel_Wel.setText(name + "老师,您好!");
                    break;
                } else {
                    jLabel_Warning.setText(warning);
                }
            }
        } catch (Exception e) {
            jLabel_Warning.setText(warning);
        }
    }

    public void jButton_Cancel_actionPerformed(ActionEvent e) {
        dispose();
        TestFrame.reset();
    }

    public void tf_ID_mouseClicked(MouseEvent e) {
        if (jLabel_Warning.getText().equals(warning)) {
            jLabel_Warning.setText("");
        }
    }

    public void pf_ID_mouseClicked(MouseEvent e) {
        if (jLabel_Warning.getText().equals(warning)) {
            jLabel_Warning.setText("");
        }
    }
}


class LogInTest_jButton_Cancel_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogInTest_jButton_Cancel_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton_Cancel_actionPerformed(e);
    }
}


class LogInTest_tf_ID_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogInTest_tf_ID_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.tf_ID_actionPerformed(e);
    }
}


class LogIn_pf_ID_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogIn_pf_ID_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.pf_ID_actionPerformed(e);
    }
}


class LogInTest_tf_ID_mouseAdapter extends MouseAdapter {
    private LogInTest adaptee;
    LogInTest_tf_ID_mouseAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tf_ID_mouseClicked(e);
    }
}


class LogInTest_pf_ID_mouseAdapter extends MouseAdapter {
    private LogInTest adaptee;
    LogInTest_pf_ID_mouseAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.pf_ID_mouseClicked(e);
    }
}


class LogIn_jRadioButton2_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogIn_jRadioButton2_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jRadioButton2_actionPerformed(e);
    }
}


class LogIn_jRadioButton1_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogIn_jRadioButton1_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jRadioButton1_actionPerformed(e);
    }
}


class LogIn_button_Confirm_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogIn_button_Confirm_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.button_Confirm_actionPerformed(e);
    }
}


class LogIn_button_Reset_actionAdapter implements ActionListener {
    private LogInTest adaptee;
    LogIn_button_Reset_actionAdapter(LogInTest adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.button_Reset_actionPerformed(e);
    }

}

⌨️ 快捷键说明

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