📄 logintest.java~66~
字号:
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(275, 270);
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( -1, 0, 270, 61));
label_cat.setFont(new java.awt.Font("黑体", Font.BOLD, 20));
label_cat.setText("登录身份:");
label_cat.setBounds(new Rectangle(0, 64, 120, 34));
label_ID.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
label_ID.setText("用户姓名:");
label_ID.setBounds(new Rectangle(0, 104, 120, 34));
label_pwd.setFont(new java.awt.Font("华文行楷", Font.BOLD, 20));
label_pwd.setText("登录密码:");
label_pwd.setBounds(new Rectangle(0, 149, 120, 34));
this.getContentPane().setBackground(SystemColor.text);
button_Reset.setBounds(new Rectangle(87, 193, 75, 30));
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(0, 193, 75, 30));
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(96, 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(96, 149, 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(97, 68, 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(164, 68, 66, 25));
jRadioButton2.addActionListener(new LogIn_jRadioButton2_actionAdapter(this));
jButton_Cancel.setBounds(new Rectangle(176, 193, 75, 30));
jButton_Cancel.setFont(new java.awt.Font("华文彩云",
Font.BOLD | Font.ITALIC, 20));
jButton_Cancel.setText("退出");
jButton_Cancel.addActionListener(new
LogInTest_jButton_Cancel_actionAdapter(this));
this.getContentPane().add(label_wel);
this.getContentPane().add(label_cat);
this.getContentPane().add(jRadioButton1);
this.getContentPane().add(jRadioButton2);
this.getContentPane().add(label_ID);
this.getContentPane().add(tf_ID);
this.getContentPane().add(label_pwd);
this.getContentPane().add(pf_ID);
this.getContentPane().add(button_Confirm);
this.getContentPane().add(jButton_Cancel);
this.getContentPane().add(button_Reset);
}
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();
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("");
}
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();
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 {
JOptionPane.showMessageDialog(this,
"用户名或密码错误!请检查您输入的信息是否正确!\n如有其他问题请与管理员联系。",
"登陆失败!",
1);
}
}
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 {
JOptionPane.showMessageDialog(this,
"用户名或密码错误!请检查您输入的信息是否正确!\n如有其他问题请与管理员联系。",
"登陆失败!",
1);
}
}
} catch (Exception e) {
}
}
public void jButton_Cancel_actionPerformed(ActionEvent e) {
dispose();
TestFrame.reset();
}
}
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;
}
}
class LogInTest_pf_ID_mouseAdapter extends MouseAdapter {
private LogInTest adaptee;
LogInTest_pf_ID_mouseAdapter(LogInTest adaptee) {
this.adaptee = adaptee;
}
}
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 + -