📄 changepassworddialog.java
字号:
package librarysearchingsystem;
import javax.swing.JDialog;
import javax.swing.JLabel;
import java.awt.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.UIManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;
public class ChangePasswordDialog extends JDialog implements ActionListener {
private final int width = 350;
private final int height =200;
Frame f;
public ChangePasswordDialog(Frame f) {
this.f = f;
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(width, height);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((d.width - width) / 2, (d.height - height) / 2);
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel1.setForeground(SystemColor.inactiveCaption);
jLabel1.setText("原密码:");
jLabel1.setBounds(new Rectangle(17, 15, 122, 23));
this.getContentPane().setLayout(null);
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel2.setForeground(UIManager.getColor(
"FormattedTextField.selectionBackground"));
jLabel2.setText("新密码");
jLabel2.setBounds(new Rectangle(17, 51, 122, 23));
noButton.setBounds(new Rectangle(196, 115, 69, 31));
noButton.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
noButton.setText("取消");
yesButton.setBounds(new Rectangle(47, 115, 69, 31));
yesButton.setFont(new java.awt.Font("隶书", Font.PLAIN, 16));
yesButton.setText("确定");
xYLayout1.setWidth(327);
xYLayout1.setHeight(155);
this.setResizable(false);
this.setTitle("修改密码");
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
jLabel3.setForeground(new Color(49, 106, 197));
jLabel3.setText("再次输入新密码");
jLabel3.setBounds(new Rectangle(17, 81, 117, 29));
oldPasswordField.setText("");
oldPasswordField.setBounds(new Rectangle(169, 15, 150, 23));
newPasswordField.setText("");
newPasswordField.setBounds(new Rectangle(169, 51, 150, 23));
newPasswordField2.setText("");
newPasswordField2.setBounds(new Rectangle(169, 81, 150, 23));
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(oldPasswordField);
this.getContentPane().add(newPasswordField);
this.getContentPane().add(newPasswordField2);
this.getContentPane().add(jLabel3);
this.getContentPane().add(yesButton, null);
this.getContentPane().add(noButton, null);
yesButton.addActionListener(this);
noButton.addActionListener(this);
this.setModal(true);
this.setVisible(true);
}
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JButton yesButton = new JButton();
JButton noButton = new JButton();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JPasswordField oldPasswordField = new JPasswordField();
JPasswordField newPasswordField = new JPasswordField();
JPasswordField newPasswordField2 = new JPasswordField();
public void actionPerformed(ActionEvent e) {
this.dispose();
if (e.getSource() == yesButton) {
if (check()) {
f.stu.changePasswordTo(String.valueOf(newPasswordField.getPassword()));
}
}
}
private boolean check() {
// this.dispose();
char ch[] = oldPasswordField.getPassword();
if (!f.stu.password.equals(String.valueOf(ch))) {
// this.dispose();
new TipsDialog("原密码输入错误");
return false;
}
ch = newPasswordField.getPassword();
if (ch.length < 6 || ch.length > 15) {
// this.dispose();
new TipsDialog("密码长度不在6~15之间");
return false;
}
char ch2[] = newPasswordField2.getPassword();
if (String.valueOf(ch).equals(String.valueOf(ch2))) {
new TipsDialog("密码修改成功");
return true;
} else {
new TipsDialog("两个新密码不同");
return false;
}
}
public static void main(String[] args) {
new ChangePasswordDialog(null);
}
/** @todo 未作事件部分 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -