Java 模拟ATM 如何修改密码

运行时修改了密码,但是再次登录时还是原密码

public class ChangePassword extends Frame implements ActionListener{

Panel panel1 = new Panel();

Panel panel2 = new Panel();

Panel panel3 = new Panel();

Panel panel = new Panel();

JPasswordField tf4,tf5,tf6;

Button button;

Account act;

ChangePassword(String s,Account act){

super(s);

this.act=act;

tf4 = new JPasswordField(6);

tf5 = new JPasswordField(6);

tf6 = new JPasswordField(6);

button = new Button("确定");

button.addActionListener(this);

/*建立新密码*/

panel1.add(new Label("请输入你的旧密码:"));

panel1.add(tf4);

panel2.add(new Label("请输入你的新密码:"));

panel2.add(tf5);

panel3.add(new Label("请再次输入新密码:"));

panel3.add(tf6);

panel.add(button);

this.add(panel1);

this.add(panel2);

this.add(panel3);

this.add(panel);

setLayout(new GridLayout(4,1));

setBounds(200,200,300,200);

this.setVisible(true);

/*** 窗口事件, 判断窗口是否关闭*/

this.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(0);

}

});

}

/**判断事件源,看条件是否成立再修改密码*/

public void actionPerformed(ActionEvent e){

if(e.getSource()==button){

String pwd2,pwd3,pwd4,pwd1;

char [] p2,p3,p4;

pwd1 = act.getPassword();

p2=tf4.getPassword();

p3=tf5.getPassword();

p4=tf6.getPassword();

pwd2 = new String(p2);

pwd3 = new String(p3);

pwd4 = new String(p4);

if(pwd2.equals(pwd1)){

if(pwd3.equals(pwd4)){//判断两次输入的新密码是否匹配

act.changePassword(pwd3);//启用新的密码

JOptionPane.showMessageDialog(this, "修改密码成功", "账户提示信息",JOptionPane.PLAIN_MESSAGE);

dispose();

new WindowBox("ATM") ;

//new Selection("选择",act);//返回选择服务窗口

}

else{

this.setVisible(true);

JOptionPane.showMessageDialog(this, "两次输入要修改的密码不同!", "账户提示信息",JOptionPane.ERROR_MESSAGE);

dispose();

new Selection("选择",act);

}

else{

this.setVisible(false);

JOptionPane.showMessageDialog(this, "输入密码错误!", "账户提示信息",JOptionPane.ERROR_MESSAGE);

dispose();

new Selection("选择",act);   

}

}

}

}

请先 登录 后评论

1 个回答

ttivmw28@163.com - 员工

qwe

请先 登录 后评论