java atm gui_java_ATM_GUI

importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.io.File;//import java.io.Reader;

importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JOptionPane;importjavax.swing.JPanel;//import javax.swing.JPasswordField;

importjavax.swing.JTextField;importjavax.swing.WindowConstants;public class deng_lu implementsActionListener{privateJFrame frame;private JPanel p0,p1,p2,p3,p4; //布局

privateJTextField userName;privateJTextField mi_ma,cha_mi_ma;privateJButton deng;privateJButton zhu_ce;//private Reader fw;// Boolean Zhu_ce = true; //控制是否注册的变量

publicdeng_lu() {

frame= new JFrame("登陆ATM");

frame.setResizable(false); //设置为不能放大

frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //右上角x 退出

p0 = newJPanel();

p0.add(new JLabel("银行储蓄ATM")); //标签

frame.add(p0);

p1= newJPanel();

p1.add(new JLabel("\t用 户 名:"));

userName= new JTextField(20);

p1.add(userName);

p2= newJPanel();

p2.add(new JLabel("\t 密 码:"));

mi_ma= new JTextField(20);//JPasswordField mi_ma = new JPasswordField(20) ;//mi_ma.setEchoChar('*') ;//设置回显//String mi = String.valueOf(mi_ma.getPassword());

p2.add(mi_ma);

p3= newJPanel();

deng= new JButton(" 登陆 ");

zhu_ce= new JButton(" 注册 ");

p3.add(deng);

p3.add(zhu_ce);

p4= newJPanel();

p4.add(new JLabel("确认密码:"));

cha_mi_ma= new JTextField(20);

p4.add(cha_mi_ma);

frame.add(p1);

frame.add(p2);

frame.add(p4);//确认密码框 ,放在注册键的前面

frame.add(p3);

frame.pack();

frame.setVisible(true);

p4.setVisible(false);

deng.addActionListener(this); //添加监听

zhu_ce.addActionListener(this);

frame.setBounds(200,200,350,250); //设置大小

frame.setLayout(new FlowLayout()); //流式布局

}

@Overridepublic void actionPerformed(ActionEvent e) { //动作//TODO Auto-generated method stub

if(e.getActionCommand().equals(" 注册 ")) { //如果点击注册

if(p4.isVisible() == false) { //判断部件是否可见

p4.setVisible(true);

deng.setText(" 取消 "); //将登陆改为取消,同时触发取消监听器

Zhu_ce = true;return;

}if(Zhu_ce == true) {if(userName.getText().equals("")) { //如果userName文本为空

JOptionPane.showMessageDialog(frame, "用户名不能为空"); //弹窗

return;

}else{for (int i = 0;i

JOptionPane.showMessageDialog(frame,"该用户已被注册");

userName.setText(""); //清空输入框

mi_ma.setText("");

cha_mi_ma.setText("");return; //若用户名同名,结束方法

}

}

}if(mi_ma.getText().length()!=6) { //&&mi_ma.getText().equals("")

JOptionPane.showMessageDialog(frame, "请输入六位密码"); //弹窗

return;

}else{if(cha_mi_ma.getText().equals(mi_ma.getText())) {//注册账户,账户实例化

zhanghu zhang_zhu_ce = new zhanghu(userName.getText(),mi_ma.getText(),"0");

JOptionPane.showMessageDialog(frame,"注册成功,请登陆");

Test.usersList.add(zhang_zhu_ce);//加入Test类的静态用户list

Test.usersUpdate();return;

}else{

JOptionPane.showMessageDialog(frame,"两次输入的密码不一致,请重新输入");return;

}

}

}

}if(e.getActionCommand().equals(" 登陆 ")) {for(int i = 0;i

JOptionPane.showMessageDialog(frame,"登陆成功");

Test.d_zhanghu=Test.usersList.get(i);//将list中符合登陆输入密码的账户类设为当前Test类中的静态的“当前类”

Test.file = new File(Test.d_zhanghu+".text"); //在文件中添加新的txt

Menu menu= new Menu(); //实例化菜单窗口

Test.menu=menu;

frame.setVisible(false); //隐藏登陆窗口

return;

}else{

JOptionPane.showMessageDialog(frame,"密码错误");

cha_mi_ma.setText(""); //清空

return;

}

}

}

JOptionPane.showMessageDialog(frame,"该用户不存在");

}if(e.getActionCommand().equals(" 取消 ")) {

p4.setVisible(false); //隐藏窗口

deng.setText(" 登陆 ");

Zhu_ce= false; //不可注册

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值