ATM自动取款机 JAVA代码实现

ATM自动取款机 JAVA代码实现

ID:37908861

大小:71.50 KB

页数:15页

时间:2019-06-02

上传者:U-2437
ATM自动取款机 JAVA代码实现_第1页
ATM自动取款机 JAVA代码实现_第2页
ATM自动取款机 JAVA代码实现_第3页
ATM自动取款机 JAVA代码实现_第4页
ATM自动取款机 JAVA代码实现_第5页
资源描述:

《ATM自动取款机 JAVA代码实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

importjava.awt.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.*;/**************************Account类************************************/classAccount{privateStringcode=null;//信用卡号privateStringuname=null;//客户姓名privateStringpword=null;//客户密码privatedoublemoney=0.0;//卡里金额/******************set,get方法*******************/publicAccount(Stringcode,Stringname,Stringi,doublemoney){this.code=code;this.uname=name;this.pword=i;this.money=money;}protectedStringget_Code(){returncode;}protectedStringget_Name(){returnuname;}protectedvoidset_Password(Stringstr){pword=str;}protectedStringget_Password(){returnpword;}publicdoubleget_Money(){returnmoney;} /*得到剩余的钱的数目*/publicvoidget_Balance(doublemon){money=money-mon;}publicvoidgive_Balance(doublemon){money=money+mon;}}publicclasslogintest1{publicstaticAccountuser;/********************************查询类**********************************/staticclassre_infoimplementsActionListener{privatestaticfinallongserialVersionUID=1L;JLabelshow=newJLabel("");JLabelinfo=newJLabel("您当前的可用余额为:");JFramejf=newJFrame(""+user.get_Name()+"您好,欢迎来到查询界面");privateJButtonback=newJButton("返回");publicre_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);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==back){show.setText("退出");jf.dispose();}} }/*****************************修改密码类*********************************/staticclassset_passwordimplementsActionListener{Stringmoney;Stringnewpassword[]=newString[2];intcount=0;privateJFramejf=newJFrame(""+user.get_Name()+"您好,欢迎来到ATM修改密码界面");JLabellb1=newJLabel("请输入您的新密码");JLabellb2=newJLabel("");JLabelshow=newJLabel("");JButtonjb1=newJButton("确定");//输完金额后确定JButtonjb2=newJButton("取消");//退出放入的钱,终止存款操作JButtonjb3=newJButton("返回");//退出存款界面privateJLabel[]jlarray={lb1,lb2,show};privateJButton[]jbarray1={jb1,jb2,jb3};JTextFieldinput1=newJTextField(6);//用来输入密码JTextFieldinput2=newJTextField(6);publicset_password(){jf.setLayout(null);jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);for(inti=0;i<3;i++){jbarray1[i].addActionListener(this);jf.add(jbarray1[i]);jf.add(jlarray[i]);}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);}publicvoidactionPerformed(ActionEvente) {if(e.getSource()==input1){newpassword[0]=input1.getText();jb1.requestFocus();show.setText(null);}elseif(e.getSource()==input2){newpassword[1]=input1.getText();jb1.requestFocus();show.setText(null);}elseif(e.getSource()==jb1){count++;if(count==2){intk=0;for(intj=0;j0){if(a50){show.setText("每次取款金额不能超过5000元");input.setText("");}elseif(a<0) {show.setText("取款不能为负");input.setText("");}}elseif(e.getSource()==jb8){input.setText("");}elseif(e.getSource()==jb9){jf.dispose();}elseif(e.getSource()==jb1){jb7.requestFocus();count=100;}elseif(e.getSource()==jb2){jb7.requestFocus();count=300;}elseif(e.getSource()==jb3){jb7.requestFocus();count=500;}elseif(e.getSource()==jb4){jb7.requestFocus();count=1000;}elseif(e.getSource()==jb5){jb7.requestFocus();count=2000;}else{if(count<=user.get_Money()){show.setText("恭喜您成功取款"+count+"元,请在30秒内取走您的钱");user.get_Balance(count); }elseshow.setText("余额不足");}}}/********************************存款类**********************************/staticclassgive_balanceimplementsActionListener{privatestaticfinallongserialVersionUID=1L;intcount=0;privateJFramejf=newJFrame(""+user.get_Name()+"您好,欢迎来到ATM模拟存款界面");JLabellb1=newJLabel("请放入您将要存的钱");JLabelshow=newJLabel("");JButtonjb1=newJButton("确定");//输完金额后确定JButtonjb2=newJButton("取消");//退出放入的钱,终止存款操作JButtonjb3=newJButton("返回");//退出存款界面privateJLabel[]jlarray={lb1,show};privateJButton[]jbarray1={jb1,jb2,jb3};JTextFieldinput=newJTextField();//用输入来模拟放钱的过程publicgive_balance(){jf.setLayout(null);jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);for(inti=0;i<2;i++){jf.add(jlarray[i]);}for(inti=0;i<3;i++){jbarray1[i].addActionListener(this);jf.add(jbarray1[i]);}lb1.setBounds(100,100,200,20);jb1.setBounds(70,230,80,20);jb2.setBounds(160,230,80,20);jb3.setBounds(200,350,80,20);input.setBounds(100,150,100,20);show.setBounds(90,190,200,20);jf.add(input);} publicvoidactionPerformed(ActionEvente){doublea;if(e.getSource()==input){show.setText(input.getText());jb1.requestFocus();jb2.requestFocus();}if(e.getSource()==jb1){count++;if(count==2){show.setText("恭喜您,成功存款"+Double.parseDouble(input.getText())+"元");user.give_Balance(Double.parseDouble(input.getText()));input.setText(null);}elseif(count==1){a=Double.parseDouble(input.getText());if(Double.parseDouble(input.getText())>0&&a%100==0)show.setText("您是否要存入"+Double.parseDouble(input.getText())+"元");elseif(Double.parseDouble(input.getText())<0){show.setText("存款不能为负");count=0;input.setText(null);}else{show.setText("您只能存入整百金额的钱数");count=0;input.setText(null);}}}elseif(e.getSource()==jb2){show.setText("存款失败");count=0;input.setText(null); }elseif(e.getSource()==jb3){jf.dispose();}}}/*********************************登录类*********************************/staticclassloginimplementsActionListener{privatestaticfinallongserialVersionUID=1L;intcount=0;privateJFramejf=newJFrame();//创建JPanel对象JLabelusernum=newJLabel("请插入银行卡");//创建标签JLabelpassword=newJLabel("请输入密码");//创建标签JLabelshow=newJLabel("");//创建标签privateJLabel[]j1={usernum,password,show};JButtonok=newJButton("确定");//输完密码后确定JButtoncancel=newJButton("取消");JButtonquit=newJButton("退出");//重新输入密码privateJButton[]jbarray2={ok,cancel,quit};privateJTextFieldjnum=newJTextField();privateJPasswordFieldjpassword=newJPasswordField(6);//密码只能为六位数字Accountuser1=newAccount("000000","Devil","123456",50000);Accountuser2=newAccount("123456","Demo","213452",10000);Accountuser3=newAccount("111222","Jane","112233",500);Accountuser4=newAccount("222222","Lili","123123",5000);Booleanis_right(Stringunum,Stringupword){if(unum.equals(user1.get_Code())){if(upword.equals(user1.get_Password())){user=user1;returntrue;}}elseif(unum.equals(user2.get_Code())){if(upword.equals(user2.get_Password())){user=user2;returntrue;} }elseif(unum.equals(user3.get_Code())){if(upword.equals(user3.get_Password())){user=user3;returntrue;}}elseif(unum.equals(user4.get_Code())){if(upword.equals(user4.get_Password())){user=user4;returntrue;}}returnfalse;}publiclogin(){jf.setLayout(null);for(inti=0;i<2;i++){j1[i].setBounds(30,50+40*i,180,20);jbarray2[i].setBounds(30+110*i,220,80,20);jf.add(j1[i]);jf.add(jbarray2[i]);jbarray2[i].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(130,90,100,20);jf.add(jpassword);jpassword.setEchoChar('*');jpassword.addActionListener(this);j1[2].setBounds(10,180,270,20);jf.add(j1[2]);jf.setTitle("欢迎使用ATM模拟系统"); jf.setBounds(200,200,300,400);jf.setVisible(true);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@SuppressWarnings("deprecation")publicvoidactionPerformed(ActionEvente){if(e.getSource()==jnum){password.requestFocus();}elseif(e.getSource()==jpassword){jnum.requestFocus();}elseif(e.getSource()==quit){jnum.setText(null);jpassword.setText(null);System.exit(0);}elseif(e.getSource()==jbarray2[1]){j1[2].setText("");jnum.setText("");jpassword.setText("");jnum.requestFocus();}else{if(jnum.getText().equals("")){j1[2].setText("请插入银行卡");}elseif(jpassword.getText().equals("")){j1[2].setText("密码不能为空,请输入密码");}elseif((is_right(jnum.getText(),jpassword.getText()))){j1[2].setText("密码正确,欢迎使用!");newmainmenu();jf.dispose();} else{j1[2].setText("密码错误,请重新输入");password.setText("");count++;if(count==3){j1[2].setText("对不起,您的操作有误,银行卡已被吞入");jnum.setText(null);jpassword.setText(null);}}}}}/*********************************主函数********************************/publicstaticvoidmain(String[]args){newlogin();}}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
关闭