📄 changepassword.java
字号:
//ChangePassword.java
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ChangePassword extends JFrame implements ActionListener {
JPasswordField newpassword;
JLabel label;
JButton button;
Container container;
String username;
public ChangePassword(String username) {
super("修改密码");
this.username = username;
container = getContentPane();
container.setLayout(null);
setSize(250, 115);
newpassword = new JPasswordField();
newpassword.setEchoChar('*');
button = new JButton();
button.setText("确定");
label = new JLabel();
label.setText("输入新密码:");
label.setBounds(10, 10, 100, 25);
newpassword.setBounds(120, 10, 120, 25);
button.setBounds(95, 55, 60, 25);
container.add(newpassword);
container.add(label);
container.add(button);
button.addActionListener(this);
// 将窗口置于屏幕中央
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.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);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
// 取得用户输入的密码
char temp[] = newpassword.getPassword();
String tempPass = new String(temp);
CheckUser pw = new CheckUser();
if (pw.changepw(username, tempPass)) {
JOptionPane.showMessageDialog(null, "密码修改成功","信息", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "密码修改失败","警告", JOptionPane.WARNING_MESSAGE);
}
setVisible(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -