ATM自动取款机 JAVA代码实现.doc_第1页
ATM自动取款机 JAVA代码实现.doc_第2页
ATM自动取款机 JAVA代码实现.doc_第3页
ATM自动取款机 JAVA代码实现.doc_第4页
ATM自动取款机 JAVA代码实现.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;/*Account类*/class Account private String code =null; /信用卡号 private String uname =null; /客户姓名 private String pword =null; /客户密码 private double money =0.0; /卡里金额 /*set,get方法*/ public Account(String code,String name,String i,double money) this.code=code; this.uname=name; this.pword=i; this.money=money; protected String get_Code() return code; protected String get_Name() return uname; protected void set_Password(String str) pword=str; protected String get_Password() return pword; public double get_Money() return money; /*得到剩余的钱的数目*/ public void get_Balance(double mon) money =money- mon; public void give_Balance(double mon) money =money+ mon; public class logintest1public static Account user;/*查询类*/static class re_info implements ActionListenerprivate static final long serialVersionUID = 1L;JLabel show=new JLabel();JLabel info=new JLabel(您当前的可用余额为:);JFrame jf=new JFrame(+user.get_Name()+ 您好,欢迎来到查询界面);private JButton back=new JButton(返回);public re_info()jf.setLayout(null);jf.add(back);jf.add(info);back.addActionListener(this);back.setBounds(200,300,100,20);show.setBounds(100,200,100,20);info.setBounds(50,50,200,20);show.setText(user.get_Money()+);jf.setVisible(true);jf.add(show);jf.setBounds(200,200,300,400);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void actionPerformed(ActionEvent e)if(e.getSource()=back)show.setText(退出);jf.dispose();/*修改密码类*/static class set_password implements ActionListener String money;String newpassword=new String2;int count=0;private JFrame jf=new JFrame(+user.get_Name()+ 您好,欢迎来到ATM修改密码界面);JLabel lb1=new JLabel(请输入您的新密码);JLabel lb2=new JLabel();JLabel show=new JLabel();JButton jb1=new JButton(确定); /输完金额后确定 JButton jb2=new JButton(取消); /退出放入的钱,终止存款操作 JButton jb3=new JButton(返回); /退出存款界面 private JLabeljlarray=lb1,lb2,show;private JButton jbarray1=jb1,jb2,jb3;JTextField input1=new JTextField(6); /用来输入密码JTextField input2=new JTextField(6);public set_password()jf.setLayout(null);jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);for(int i=0;i3;i+)jbarray1i.addActionListener(this);jf.add(jbarray1i);jf.add(jlarrayi); lb1.setBounds(100,100,200,20); lb2.setBounds(100,180,200,20); jb1.setBounds(70,260,80,20); jb2.setBounds(160,260,80,20); jb3.setBounds(200,350,80,20); input1.setBounds(100,150,100,20); input2.setBounds(100,210,100,20); show.setBounds(50,235,330,20); jf.add(input1); jf.add(input2);public void actionPerformed(ActionEvent e)if(e.getSource()=input1) newpassword0=input1.getText();jb1.requestFocus();show.setText(null);else if(e.getSource()=input2)newpassword1=input1.getText();jb1.requestFocus();show.setText(null);else if(e.getSource()=jb1) count+;if(count=2)int k=0;for(int j=0;jinput1.getText().length();j+)if(input1.getText().charAt(j)=input2.getText().charAt(j)k+;if(k=6)show.setText(恭喜您修改成功,您的新密码为+input2.getText();count=0;user.set_Password(input1.getText();input1.setText(null);input2.setText(null);elseinput1.setText(null);input2.setText(null);show.setText(修改失败,两次输入不一致);count=0;lb2.setText(null);else if(count=1) int i=0;for(int j=0;jinput1.getText().length()-1;j+)if(input1.getText().charAt(j)=input1.getText().charAt(j+1)i+;if(input1.getText().length()6|i=input1.getText().length()-1)show.setText(密码过于简单,请重新设密码);count=0;input1.setText(null);lb2.setText(null);elselb2.setText(请再次输入密码);show.setText(null);else if(e.getSource()=jb2)input1.setText(null);input2.setText(null);count=0;lb2.setText(null);else if(e.getSource()=jb3)jf.dispose();/*主菜单类*/static class mainmenu extends Frame implements ActionListenerprivate static final long serialVersionUID = 2L;private JPanel jp=new JPanel();JLabel show=new JLabel();JButton quit=new JButton(退出);JButton inqu=new JButton(查询);JButton set_password=new JButton(修改密码);JButton get_balance=new JButton(取款);JButton give_balance=new JButton(存款);JFrame jf=new JFrame(+user.get_Name()+ 您好,欢迎进入主界面);JLabel jl1=new JLabel(请选择你想进行的操作);private JButtonjb=inqu,set_password,get_balance,give_balance,quit;public mainmenu()jf.setLayout(null);jp.setBounds(100,100,100,500);for(int i=0;i5;i+)jf.add(jbi);jbi.addActionListener(this);if(i!=4)jbi.setBounds(30,100+40*i,100,20);elsejbi.setBounds(200,330,100,20);show.setBounds(30,300,180,20);jl1.setBounds(30,50,200,20);jf.setVisible(true);jf.add(show);jf.add(jl1);jf.setBounds(200,200,300,400);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void actionPerformed(ActionEvent e)if(e.getSource()=jb0)show.setText(查询);new re_info();this.dispose();else if(e.getSource()=jb1)show.setText(重置密码);this.dispose();new set_password();else if(e.getSource()=jb2)show.setText(取款);this.dispose();new get_balance();else if(e.getSource()=jb3)show.setText(存款);this.dispose();new give_balance();else if(e.getSource()=jb4)show.setText(退出); jf.dispose();/*取款类*/static class get_balance implements ActionListener private static final long serialVersionUID = 1L;double count=0;double a;private JFrame jf=new JFrame(+user.get_Name()+ 您好,欢迎来到ATM模拟取款界面);JButton jb1=new JButton(100);JButton jb2=new JButton(300);JButton jb3=new JButton(500);JButton jb4=new JButton(1000);JButton jb5=new JButton(2000);JButton jb6=new JButton(输入);JLabel show=new JLabel();JButton jb7=new JButton(确定); /输完金额后确定 JButton jb8=new JButton(取消); /重新输入金额 JButton jb9=new JButton(返回);private JButton jbarray1=jb1,jb2,jb3,jb4,jb5,jb6,jb7,jb8,jb9;JTextField input=new JTextField(5);public get_balance()jf.setLayout(null);jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);for(int i=0;i9;i+)jbarray1i.addActionListener(this);jf.add(jbarray1i);if(i5)jbarray1i.setBounds(30,50+40*i,80,20);else if(i=5)jbarray1i.setBounds(200,213,80,20);else if(i=6)jbarray1i.setBounds(100,280,80,20); else if(i=7)jbarray1i.setBounds(200,280,80,20); else jbarray1i.setBounds(200,350,80,20);input.setBounds(200,180,80,20);show.setBounds(0,250,320,20); jf.add(input); jf.add(show);public void actionPerformed(ActionEvent e)if(e.getSource()=jb6) a=Double.parseDouble(input.getText(); if(a%100=0) &(a/100)0) if(a50) show.setText(每次取款金额不能超过5000元); input.setText(); else if(a0) show.setText(取款不能为负); input.setText(); else if(e.getSource()=jb8)input.setText();else if(e.getSource()=jb9)jf.dispose();else if(e.getSource()=jb1)jb7.requestFocus();count=100;else if(e.getSource()=jb2)jb7.requestFocus();count=300;else if(e.getSource()=jb3)jb7.requestFocus();count=500;else if(e.getSource()=jb4)jb7.requestFocus();count=1000;else if(e.getSource()=jb5)jb7.requestFocus();count=2000;elseif(count=user.get_Money()show.setText(恭喜您成功取款+count+元,请在30秒内取走您的钱);user.get_Balance(count);elseshow.setText(余额不足);/*存款类*/static class give_balance implements ActionListener private static final long serialVersionUID = 1L;int count=0;private JFrame jf=new JFrame(+user.get_Name()+您好,欢迎来到ATM模拟存款界面);JLabel lb1=new JLabel(请放入您将要存的钱);JLabel show=new JLabel();JButton jb1=new JButton(确定); /输完金额后确定 JButton jb2=new JButton(取消); /退出放入的钱,终止存款操作 JButton jb3=new JButton(返回); /退出存款界面 private JLabeljlarray=lb1,show;private JButton jbarray1=jb1,jb2,jb3;JTextField input=new JTextField();/用输入来模拟放钱的过程public give_balance()jf.setLayout(null);jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);for(int i=0;i2;i+)jf.add(jlarrayi);for(int i=0;i0&a%100=0)show.setText(您是否要存入+Double.parseDouble(input.getText()+元);else if(Double.parseDouble(input.getText()0)show.setText(存款不能为负);count=0;input.setText(null);elseshow.setText(您只能存入整百金额的钱数);count=0;input.setText(null);else if(e.getSource()=jb2)show.setText(存款失败);count=0;input.setText(null);else if(e.getSource()=jb3)jf.dispose(); /*登录类*/static class login implements ActionListenerprivate static final long serialVersionUID = 1L;int count=0;private JFrame jf=new JFrame(); /创建JPanel对象JLabel usernum = new JLabel(请插入银行卡); /创建标签JLabel password = new JLabel(请输入密码); /创建标签JLabel show = new JLabel(); / 创建标签private JLabelj1 =usernum,password,show;JButton ok=new JButton(确定); /输完密码后确定JButton cancel=new JButton(取消); JButton quit=new JButton(退出); /重新输入密码private JButton jbarray2=ok,cancel,quit;private JTextField jnum = new JTextField(); private JPasswordField jpassword = new JPasswordField(6); /密码只能为六位数字 Account user1=new Account(000000,Devil,123456,50000);Account user2=new Account(123456,Demo,213452,10000);Account user3=new Account(111222,Jane,112233,500);Account user4=new Account(222222,Lili,123123,5000);Boolean is_right(String unum,String upword)if(unum.equals(user1.get_Code()if(upword.equals(user1.get_Password()user=user1;return true;else if(unum.equals(user2.get_Code()if(upword.equals(user2.get_Password()user=user2;return true;else if(unum.equals(user3.get_Code()if(upword.equals(user3.get_Password()user=user3;return true;else if(unum.equals(user4.get_Code()if(upword.equals(user4.get_Password()user=user4;return true;return false;public login()jf.setLayout(null);for(int i=0;i2;i+)j1i.setBounds(30,50+40*i,180,20);jbarray2i.setBounds(30+110*i,220,80,20);jf.add(j1i);jf.add(jbarray2i);jbarray2i.addActionListener(this);jf.add(quit);quit.addActionListener(this);quit.setBounds(200,300,80,20);jf.setBounds(200,340,80,20);jnum.setBounds(130,50,100,20);jf.add(jnum);jnum.addActionListener(this);jpassword.setBounds

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论