📄 amendpassword.java
字号:
/****************************************
* <p>Title: ATM自动取款机</p>
*
* <p>Description: 模拟</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author vinky_sc
* @version 1.0
*****************************************/
import javax.swing.JFrame;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.UIManager;
import java.awt.Font;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import javax.swing.JOptionPane;
import java.awt.Toolkit;
/*****************************************
* 修改密码窗口
*
* 主要是修改密码
*****************************************/
public class AmendPassword extends JFrame {
Client user = new Client();
atmScreen main = new atmScreen();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JPasswordField jPasswordField2 = new JPasswordField();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JPasswordField jPasswordField3 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel5 = new JLabel();
public AmendPassword() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
this.getContentPane().setBackground(Color.lightGray);
jLabel1.setBackground(UIManager.getColor("ComboBox.selectionBackground"));
jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
this.getContentPane().setBackground(Color.lightGray);
this.setResizable(false);
setSize(new Dimension(400, 330));
setTitle("模拟ATM自动取款机--修改密码");
jLabel1.setToolTipText("");
jLabel1.setText("欢迎使用ATM自动取款机");
jLabel3.setText(" 请输入新密码:");
jLabel4.setText(" 请再输入新密码:");
jPasswordField3.setBackground(Color.cyan);
jButton1.setText("确 定");
jButton1.addActionListener(new AmendPassword_jButton1_actionAdapter(this));
jButton2.setText("取 消");
jButton2.addActionListener(new AmendPassword_jButton2_actionAdapter(this));
jLabel5.setText(" 注意:密码必须为0~9的数字组成,长度(6~10)");
this.getContentPane().add(jLabel1, new XYConstraints(103, 20, 195, 35));
this.getContentPane().add(jLabel5, new XYConstraints(67, 59, 265, 30));
jPasswordField2.setBackground(Color.cyan);
jPasswordField1.setBackground(Color.cyan);
jLabel2.setText(" 请输入你的旧密码:");
this.getContentPane().add(jButton1, new XYConstraints(89, 246, 95, 30));
this.getContentPane().add(jButton2, new XYConstraints(217, 246, 95, 30));
this.getContentPane().add(jLabel4, new XYConstraints(67, 200, 130, 30));
this.getContentPane().add(jPasswordField3,
new XYConstraints(195, 200, 100, 30));
this.getContentPane().add(jPasswordField2,
new XYConstraints(195, 150, 100, 30));
this.getContentPane().add(jLabel3, new XYConstraints(67, 149, 130, 30));
this.getContentPane().add(jPasswordField1,
new XYConstraints(195, 100, 100, 30));
this.getContentPane().add(jLabel2, new XYConstraints(67, 100, 130, 30));
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;
}
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
this.setVisible(true);
}
public void jButton2_actionPerformed(ActionEvent e) {
new menu();
this.dispose();
}
//如果修改密码不成功,将各密码框清空
public void setpass()
{
jPasswordField1.setText("");
jPasswordField2.setText("");
jPasswordField3.setText("");
}
public void jButton1_actionPerformed(ActionEvent e) {
String id = main.aa; //获取客户卡号
String pwd = user.getPAW(id); //获取客户密码
String oldpwd = new String(jPasswordField1.getPassword());//获取客户输入的旧密码
String newpaw1 = new String(jPasswordField2.getPassword());//获取客户输入的新密码
String newpaw2 = new String(jPasswordField3.getPassword());//获取客户再一次确定的新密码
int n = user.changePaw(id,pwd,oldpwd,newpaw1,newpaw2); //调用修改密码的操作,并返回执行结果是否成功
switch(n)
{
case 1:JOptionPane.showMessageDialog(this,"修改成功!请记好新密码!","提 示",JOptionPane.WARNING_MESSAGE);new menu();this.dispose();break;
case 0:JOptionPane.showMessageDialog(this,"新密码太简单!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
case -1:JOptionPane.showMessageDialog(this,"两次输入的密码不一致!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
case -2:JOptionPane.showMessageDialog(this,"原密码输入错误!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
case -3:JOptionPane.showMessageDialog(this,"新密码为空或空格!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
case -4:JOptionPane.showMessageDialog(this,"新密码不合法!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
case -5:JOptionPane.showMessageDialog(this,"新密码含有非法字符!请重新输入!","提 示",JOptionPane.WARNING_MESSAGE);setpass();break;
}
}
}
class AmendPassword_jButton2_actionAdapter implements ActionListener {
private AmendPassword adaptee;
AmendPassword_jButton2_actionAdapter(AmendPassword adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class AmendPassword_jButton1_actionAdapter implements ActionListener {
private AmendPassword adaptee;
AmendPassword_jButton1_actionAdapter(AmendPassword adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -