📄 userinfo.java
字号:
package views;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
public class UserInfo extends JInternalFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton button0;
private JButton button1;
private JPasswordField passwordField0;
private JPasswordField passwordField1;
private JPasswordField passwordField2;
private static int flag = 0;
private static String userName = null;
private static String oldPwd1 = null;
public UserInfo() {
super("修改密码", true, true, true);
getContentPane().setLayout(null);
final JLabel label = new JLabel();
label.setFont(new Font("宋体", Font.PLAIN, 15));
label.setText("原密码:");
label.setBounds(10, 24, 75, 33);
getContentPane().add(label);
final JLabel label_1 = new JLabel();
label_1.setFont(new Font("宋体", Font.PLAIN, 15));
label_1.setText("新密码:");
label_1.setBounds(10, 80, 79, 37);
getContentPane().add(label_1);
final JLabel label_2 = new JLabel();
label_2.setFont(new Font("宋体", Font.PLAIN, 15));
label_2.setText("新密码确认:");
label_2.setBounds(10, 140, 92, 37);
getContentPane().add(label_2);
button0 = new JButton();
button0.setFont(new Font("宋体", Font.PLAIN, 15));
button0.setText("确定");
button0.addActionListener(this);
button0.setBounds(10, 219, 100, 27);
getContentPane().add(button0);
button1 = new JButton();
button1.setFont(new Font("宋体", Font.PLAIN, 15));
button1.setText("取消");
button1.addActionListener(this);
button1.setBounds(136, 220, 100, 27);
getContentPane().add(button1);
passwordField0 = new JPasswordField();// 原
passwordField0.setBounds(100, 29, 100, 24);
getContentPane().add(passwordField0);
passwordField1 = new JPasswordField();// 新
passwordField1.setBounds(100, 87, 100, 24);
getContentPane().add(passwordField1);
passwordField2 = new JPasswordField();// 新确认
passwordField2.setBounds(100, 147, 100, 24);
getContentPane().add(passwordField2);
}
public void ShowFrame() {
Dimension screen = getToolkit().getScreenSize(); // 封装组件,工具包中设置屏幕大小的方法
int width = (int) ((screen.getWidth() - 250) / 2);
int height = (int) ((screen.getHeight() - 300) / 2);// 设置对象宽 ,高
this.setBounds(width, height, 250, 300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if (arg0.getSource() == button0) // 确定
{
String oldPwd2 = passwordField0.getText();
String newPwd = passwordField1.getText();
String lastPwd = passwordField2.getText();
if (oldPwd2.equals(oldPwd1)) {// 密码合理
if (newPwd.equals(lastPwd)) {
if (flag == 1) {
System.out.println("管理员修改密码");
} else if (flag == 2) {
System.out.println("教师修改密码");
}
} else {
JOptionPane.showMessageDialog(this,"确认密码输入错误");
passwordField2.setText("");
}
}
/**/
else {
JOptionPane.showMessageDialog(this,"原密码输入错误");
passwordField0.setText("");
passwordField1.setText("");
passwordField2.setText("");
}
}else if (arg0.getSource() == button1)// 取消
{
this.setVisible(false);
}
}
public static int getFlag() {
return flag;
}
public void setFlag(int flag) {
UserInfo.flag = flag;
}
public static String getOldPwd1() {
return oldPwd1;
}
public void setOldPwd1(String oldPwd1) {
UserInfo.oldPwd1 = oldPwd1;
}
public static String getUserName() {
return userName;
}
public void setUserName(String userName) {
UserInfo.userName = userName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -