📄 uservalidateframe.java~25~
字号:
package 设备管理系统2;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.GridLayout;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class UserValidateFrame extends JFrame implements ActionListener{
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public UserValidateFrame() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(400,300);
this.setResizable(false);
contentPane=(JPanel) getContentPane();
contentPane.setLayout(null);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = getSize();
setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 22));
jLabel1.setToolTipText("");
jLabel1.setText("欢迎进入档案管理");
jLabel1.setBounds(new Rectangle(79, 9, 194, 50));
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel2.setText("用户名:");
jLabel2.setBounds(new Rectangle(77, 64, 88, 32));
jTextField1.setBounds(new Rectangle(143, 67, 200, 26));
jTextField1.setText("chaosheng");
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel3.setToolTipText("");
jLabel3.setText("密 码:");
jLabel3.setBounds(new Rectangle(77, 115, 82, 29));
contentPane.setToolTipText("");
jPasswordField1.setCaretColor(Color.orange);
// jPasswordField1.setDisabledTextColor(new UIManager(172, 168, 153));
jPasswordField1.setText("");
jPasswordField1.setBounds(new Rectangle(143, 118, 200, 27));
// jPasswordField1.setActionCommand();
jButton1.setBounds(new Rectangle(109, 184, 85, 32));
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 20));
jButton1.setToolTipText("");
jButton1.setText("确 定");
jButton1.addActionListener(this);
jButton2.addActionListener(this);
setVisible(true);
jButton2.setBounds(new Rectangle(248, 183, 93, 32));
jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jButton2.setText("取 消");
contentPane.add(jLabel1);
contentPane.add(jLabel2);
contentPane.add(jTextField1);
contentPane.add(jLabel3);
contentPane.add(jPasswordField1);
contentPane.add(jButton1);
contentPane.add(jButton2);
}
public void actionPerformed(ActionEvent event){
Object source = event.getSource();
String userName=jTextField1.getText().toString();//&&userName=="chaosheng"
char[] password= jPasswordField1.getPassword();
if (source==jButton1)
{ if(isPasswordCorrect(password))
new FileSystemMainMenu();
else JOptionPane.showMessageDialog(contentPane,"你输入的密码不正确");
}
else if (source==jButton2)
{ //this.dispose();
new FileSystemMainMenu();
}
}
private static boolean isPasswordCorrect(char[] password)
{boolean iscorrect=true;
char[] correctPassword={'b','l','e','s','s','m','e'};
if(password.length!=correctPassword.length)
iscorrect=false;
else{
for(int i=0;i<password.length;i++)
{if(password[i]!=correctPassword[i])
iscorrect=false;
}
}
for(int i=0;i<correctPassword.length;i++)
correctPassword[i]=0;
return iscorrect;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -