java项目 ATM银行系统 源代码
- 格式:doc
- 大小:319.50 KB
- 文档页数:44
ATM自助取款机系统java代码(大全)第一篇:ATM自助取款机系统java代码(大全)public void actionPerformed(ActionEvent e)//界面显示控制 {String IC_Number=“";String password=”“;String IC_No=”“;z30.setVisible(false);floatleftmoney=0;floatmoneys=0;float mon=0;float money1=0;float money2=0;if(true){int No_50=0,No_100=0;String strin=”select NO_50,NO_100 from ATM ATM_ID='123456789'“;ResultSetrsSQLSelect=executeQuery(stri n);try{ if(rsSQLSelect.next()){No_50=Integer.parseInt(rsSQLSelect.getString(”NO_50“));No_100=Integer.parseInt(rsSQLSelect.getString(”NO_100“));where}}catch(Exception er){System.out.println(”查询ATM机信息出错!“);}if(No_50==0&&No_100==0){z1.setVisible(false);t1.setText(”对不起,本ATM自动取款机暂停服务!“);cl.show(c,”1“);}}cl.show(c,”1“);if(e.getSource()==z1){t3.setText(”“);text1.setText(”“);cl.show(c,”2“);}if(e.getSource()==z4||e.getSource()==z6||e.getSource()==z1 1||e.getSource()==z16||e.getSource()==z18||e.getSource()==z22) { closeDBConnectio n();cl.show(c,”1“);}if(e.getSource()==z2){ closeDBConnection();System.exit(0);}if(e.getSource()==z3){ IC_Number=text1.getText().trim();if(getname(IC_Number)){z5.setVisible(true);pw1.setVisible(true);t4.setVisible(true);pw1.setText(”“);t5.setText(”“);cl.show(c,”3“);}else{t3.setText(”您输入的卡号不存在,请重新输入!“);cl.show(c,”2“);}}if(e.getSource()==z5){password=pw1.getText().trim();IC_Number=text1.getText().tr im();if(!login(IC_Number,password)){t5.setText(”您输入的密码错误,请重新输入!“);pw1.setText(”“);n--;cl.show(c,”3“);}else{t5.setText(”“);cl.show(c,”4“);}if(n<0){n=2;t5.setText(”您已经三次输入错误密码,谢谢您的使用,欢迎下次光临!“);z5.setVisible(false);pw1.setVisible(false);t4.setVisible(false);cl.show(c,”3“);}}if(e.getSource()==z7){t33.setText(”“);cl.show(c,”5“);}if(e.getSource()==z8)//余额查询 { DBAccess d=new DBAccess();String str3=”“;String stri=”“;IC_Number=text1.getText().trim();t29.setText(IC_Number);leftmoney=getmoney(IC_Number);t30.setText(Float.toString(leftmoney));stri=”selectbank_name from IC,bank where IC.bank_NO=bank.bank_NO and IC_ID='“+IC_Number+”'“;ResultSetrsSQLSelect=d.executeQu ery(stri);try{if(rsSQLSelect.next()){str3=rsSQLSelect.getString(”bank_name“);//mit();}} catch(Exception er){}t32.setText(str3);cl.show(c,”10“);}if(e.getSource()==z9){t23.setText(”“);cl.show(c,”9“);}if(e.getSource()==z10){t28.setText(”“);cl.show(c,”11“);}if(e.getSource()==z12){ DBAccess d=new DBAccess();IC_Number=text1.getText().trim();fetchmoney=Integ er.parseInt(text2.getText());if(fetchmoney<=0){t9.setText(”取款金额非法!请重新输入!“);text2.setText(”“);cl.show(c,”6“);return;}if(fetchmoney>1000){t9.setText(”每次交易金额最大为1000元!“);text2.setText(”“);cl.show(c,”6“);return;}if(fetchmoney%50!=0){t9.setText(”取款金额只能为50的倍数!“);text2.setText(”“);cl.show(c,”6“);return;} leftmoney=getmoney(IC_Number);if(fetchmoney>leftmoney){t9.setText(”您的余额不足,请重新输入取款金额!“);text2.setText(”“);cl.show(c,”6“);return;}int No_50=0,No_100=0,x_50=0,x_100=0,mo=0;String str1=”select NO_50,NO_100 from ATM where ATM_ID='123456789'“;ResultSetrsSQLSelect=d.executeQuery(s tr1);try{ if(rsSQLSelect.next()){No_50=Integer.parseInt(rsSQLSelect.getString(”NO_50“));No_100=Integer.parseIn t(rsSQLSelect.getString(”NO_100“));}}catch(Exception er){System.out.println(”查询ATM机信息出错!“);}x_100=fetchmoney/100;if(No_100{ mo=fetchmoney-No_100*100;x_50=mo/50;if(x_50>No_50){t9.setText(”取款机现钞不足!“);text2.setText(”“);cl.show(c,”6“);return;}else{No_50=No_50-x_50;No_100=0;}}else{No_100=No_100-x_100;x_50=(fetchmoney-x_100*100)/50;if(x_50>No_50){t9.setText(”取款机50面值现钞不足!“);text2.setText(”“);cl.show(c,”6“);return;}else{No_50=No_50-x_50;}}String str2=”update ATM set NO_50=“+No_50+” where ATM_ID='“+ATM_id+”'“;String str3=”update ATM set NO_100=“+No_100+” whereATM_ID='“+ATM_id+”'“;d.executeUpdate(str2);d.executeUpd ate(str3);setmoney(fetchmoney,IC_Number);t12.setText(Float.toString(fetchmoney));cl.show(c,”7“);text2.setText(”");第二篇:ATM取款机java课程设计黄淮学院JAVA 课程设计报告题目:《ATM柜员机》课程设计学院:信息工程学院专业:计算机科学与技术指导老师:二0一三年六月目录课程设计过程概述.......................................................................................3 2 课程设计题目描述和基本设计要求...........................................................3 3 系统需求分析...............................................................................................3 3.1 功能需求分析···················································································· 3 3.2 其他需求分析.................................................................................... 4 4 系统设计........................................................................................................4 4.1 总体设计........................................................................................... 4 4.2 ATM柜员机界面设计......................................................................... 5 4.3 各功能模块设计.. (7)4.3.1 登陆页面模块设计............................................................. 7 4.3.2 选择服务模块设计............................................................. 8 4.3.3 取款模块设计..................................................................... 9 4.3.4 修改密码模块设计............................................................. 9 4.3.5 退卡模块设计. (10)4.4 异常处理情况说明.......................................................................... 10 5 系统实现与测试.........................................................................................11 6 课程设计总结.............................................................................................13 6.1 遇到的问题及解决办法.................................................................. 13 6.2 心得体会......................................................................................... 14 参考文献..........................................................................................................15 附录 (15)ATM初始账号:000000初始密码:123456ATM柜员机课程设计过程概述2013年6月,JAVA课程设计在1#楼六楼机房进行,持续时间为两周。
本科毕业论文(设计)银行存取款系统的设计与实现姓名:__ ________ 系别: 计算机与信息技术学院_专业:_ 计算机科学与技术_ 学号:__ _____指导教师:__ _ _________年月日目录引论 (1)1银行存取款系统概述 (1)1.1背景 (1)1.2意义 (1)2 银行存取款系统需求分析 (1)2.1系统需求 (1)2.2功能需求 (1)2.2.1用户注册和登陆功能 (1)2.2.2用户存取款转账和查询历史功能 (1)2.3软件属性需求 (2)2.4业务流程描述 (2)3.银行存取款系统总体设计 (2)3.1系统设计概述 (2)3.2注册帐户 (2)3.3登录 (2)3.4存款 (2)3.5取款 (2)3.6转账 (2)3.7查询历史 (2)3.8退出 (3)4 Oracle数据库的设计 (3)4.1 Oracle数据库设计概论 (3)4.2 表的结构设计 (3)4.2.1用户表 (3)4.2.2历史表 (3)4.3 PL/SQL存储过程的设计 (3)4.3.1用户表存储过程的设计 (4)4.3.2历史表存储过程的设计 (4)5 银行存取款系统的实现 (5)5.1用户登陆模块的实现 (5)5.1.1界面样式 (5)5.1.2功能实现 (5)5.2新用户注册模块的实现 (6)5.2.1界面样式 (6)5.2.2功能实现 (6)5.3用户操作模块的实现 (7)5.3.1界面样式 (8)5.3.2功能实现 (8)5.4存款模块的实现 (9)5.4.1界面样式 (9)5.4.2功能实现 (9)5.5取款模块的实现 (10)5.5.1界面样式 (11)5.5.2功能实现 (11)5.6转账模块的实现 (12)5.6.1界面样式 (12)5.6.2功能实现 (12)5.7查询历史记录模块的实现 (15)5.7.1界面样式 (15)5.7.2功能实现 (15)6发布程序及分包规范 (16)结论 (16)参考文献 (17)致谢 (17)银行存取款系统的设计与实现摘要计算机科学技术的发展不仅极大地促进了整个科学的发展,而且明显加快了经济信息化和社会信息化的进程。
代码分为4个部分卡类,ATM类,操作人类,测试类卡类public class Card {String name;double caryue;String password;int carstatus=1;public Card(String password,double caryue){ this.caryue=caryue;this.password=password;}}ATM类import java.util.Scanner;public class ATM {String name;double atmyue;Scanner in=new Scanner(System.in);public ATM(String name,double atmyue){=name;this.atmyue=atmyue;}//验证卡密码boolean checkCard(Card car){boolean a=false;boolean b=true;System.out.println("请输入密码");int count=0;while(b){String inmima;inmima=in.next();count++;if(inmima.equals(car.password)){a=true;return a;}if(count==3){car.carstatus=0;break;}else{System.out.println("密码错误");}}return a;}boolean checkCardstatus(Card car){if(car.carstatus==0){System.out.println("卡已被锁");return false;}return true;}int getMoney(Card car){System.out.println("请输入要取款的金额");int getmoney;getmoney=in.nextInt();if(getmoney>atmyue){return 0;}if(getmoney>car.caryue){return 1;}atmyue-=getmoney;car.caryue-=getmoney;return 2;}void saveMoney(Card car){System.out.println("请输入您要存款的金额");int saveMoney;saveMoney=in.nextInt();atmyue+=saveMoney;car.caryue+=saveMoney;}void tuiCard(Card car){System.out.println(car.caryue);}void OpenCard(Card car){boolean check1=checkCard(car);if(check1){boolean check2=checkCardstatus(car);if(check2){while(true){System.out.println("请选择您的操作");System.out.println("1:取款");System.out.println("2:存款");System.out.println("3:查询");int caozuo=in.nextInt();switch(caozuo){case 1:int a=getMoney(car);while(true){if(a==0){System.out.println("sorryATM余额不足");}if(a==1){System.out.println("卡余额不足");}if(a==2){System.out.println("取款成功,请收好您的现金");}System.out.println("您是否继续取钱 0退卡");int tuika0=in.nextInt();if(tuika0==0){break;}}break;case 2:while(true){saveMoney(car);System.out.println("您是否继续存钱 0退卡");int tuika1=in.nextInt();if(tuika1==0){break;}}break;case 3:tuiCard(car);break;}System.out.println("您是否继续操作卡片任意键退卡 1继续");int tuika2=in.nextInt();if(tuika2!=1){System.out.println("退卡成功,请收好您的卡片");break;}}}else{System.out.println("密码有误");}}}}操作人类public class Person {String name;String sex;public Person(String name,String sex){=name;this.sex=sex;}void chaCrad(ATM atm,Card car,Person person){String sex1=person.sex;if(sex1.equals("男")){System.out.println("尊敬的"+name+"先生欢迎使用"++"ATM");}else{System.out.println("尊敬的"+name+"女士欢迎使用"++"ATM");}atm.OpenCard(car);}}测试类public class Test {public static void main(String[] args) {Person dan=new Person("Rocky_单","男");Card car=new Card("654321",20000);ATM atm=new ATM("工商",10000000);dan.chaCrad(atm, car,dan);}}欢迎您的下载,资料仅供参考!致力为企业和个人提供合同协议,策划案计划书,学习资料等等打造全网一站式需求。
ATM柜员机模拟程序摘要使用图形用户界面。
当输入给定的卡号和密码(初始卡号为123456和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:查询余额:初始余额为50000元ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
ATM存款:不能出现负存款。
修改密码:只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
我所设计的ATM柜员机主要是由登录页面模块还由选择服务模块组成,其中选择服务模块又由取款模块、查询余额模块、修改密码模块、退卡模块组成。
一个系统界面的好坏直接影响到用户的操作,界面设计要求样式美观、简单明了、方便易操作。
我设计的界面主要分为窗体、菜单、按钮和文本输入框几个部分,分别执行相应的操作。
.关键字:图形用户界面;ATM;柜员机;模拟程序;模块;}ATM machines simulation programAbstractUse the graphical user interface. When the input given card number and password (initial card number for 123456 and password for 123456), the system can login ATM machines system, users can according to the following rules:Inquires the balance: initial balance is 50000 yuan ATM withdrawals: every time a multiple of the amount of, the total will not more than 5000 yuan, the amount of withdrawals allows no overdraft.ATM deposits: can't negative deposits.Change the password: only the correct password is old, the new password accords with a requirement, and two enter the same case can be modified successfully password.!I designed by ATM machines is mainly composed of the login page module by choice service module is, selecting the service module by withdrawals and module, inquires module, modify the password balance module, return card modules. A system interface has a direct influence on the user's operation, interface design requirements style beauty, simple and clear, make the operation easy. I design interface are divided into form, menu, button and text input box sectionsKeywords:graphical user interface; ATM; Automated Teller Machine; simulation program; module;1 系统需求分析功能需求分析本ATM柜员机的主要功能如下所述:要求使用图形用户界面。
合肥学院计算机科学与技术系课程设计报告2013~2014学年第一学期课程面向对象课程设计课程设计名称自动取款机模拟程序学生姓名夏中雨学号1204013021专业班级12计本(3)指导教师胡春玲、张贯虹20 13年12月一、前言 3二、需求分析 31、功能需求 3A、管理端方面 3B、客户端方面 32、基本的安全控制机制。
43、性能需求: 44、出错处理需求 4三、设计理论和环境 41、系统设计理论 42、系统设计环境 4四、系统数据库设计 41、数据库构建语句 42、表构建语句 5五、总体设计 5B、管理端界面 53、删除银行卡账户对话框: 74、查询: 75、显示全部: 8C、客户端界面 92、客户端操作界面 103、余额查询 104、修改密码 115、存款 116、取款 12六、具体设计 121、各类主要功能及相互关系。
122、关键代码。
13(2)、删除银行卡 14(3)、验证客户登陆 15(4)、余额查询 16(5)、修改密码 17(7)、取款 19(8)、连接数据库 21七、总结 21八、参考文献 221、前言基于进一步巩固、加深学生所学专业课程《JAVA语言教程》的基本理论知识,理论联系实际,进一步培养学生综合分析问题,解决问题的能力的考虑和全面考核学生所掌握的基本理论知识及其实际业务能力,从而达到提高学生素质的最终目的。
学院进行了此项课程设计教学活动,此次课程设计的主要任务是为了训练同学们利用所学知识,开发小型应用系统,掌握运用JAVA语言编写调试应用系统程序,训练独立开发应用系统,进行数据处理的综合能力。
针对这次课程设计任务,我对于给定的题目,进行了详细分析,理清了思路,弄明白了应该分几步走,每一步应该怎么走。
顺利完成了课程设计任务。
项目任务要求:1、程序分为两部分:管理端和客户端。
2、管理端负责管理所有的银行卡,管理员(省略身份验证)可以增加和删除银行卡。
(1)每张银行卡由卡号唯一标识,卡号由12位阿拉伯数字组成;(2)新增的银行卡密码均为“123456”,卡内金额均为0元;(3)只有管理员增加的银行卡才能登陆客户端;(4)删除后的银行卡将不能再登陆客户端。
Java银行账户管理系统代码简介银行账户管理系统是一个用于管理银行客户账户的软件系统。
该系统可以实现客户开户、存款、取款、转账等基本功能,同时提供了查询账户余额、查询交易记录等附加功能,便于客户管理自己的资金。
功能模块客户管理模块这个模块包括客户信息的增删改查功能。
系统可以记录客户的姓名、身份证号、手机号等基本信息。
账户管理模块这个模块包括账户的开户、销户、存款、取款、转账等功能。
代码实现客户类public class Customer {private String name;private String idCard;private String phoneNumber;// 构造方法public Customer(String name, String idCard, String phoneNumber) { = name;this.idCard = idCard;this.phoneNumber = phoneNumber;}// getter和setter方法public String getName() {return name;}public void setName(String name) { = name;}public String getIdCard() {return idCard;}public void setIdCard(String idCard) {this.idCard = idCard;}public String getPhoneNumber() {return phoneNumber;}public void setPhoneNumber(String phoneNumber) {this.phoneNumber = phoneNumber;}}账户类```java public class Account { private String accountNumber; private double balance; private Customer customer;// 构造方法public Account(String accountNumber, Customer customer) {this.accountNumber = accountNumber;this.customer = customer;}// 存款public void deposit(double amount) {balance += amount;}// 取款public void withdraw(double amount) {if (balance >= amount) {balance -= amount;} else {System.out.println(\。
//初始密码为123456import java.awt.*;import java.awt.event.*;import javax.swing.*;public class MyATM extends JFrame implements ActionListener{JPanelpanelfirst,panelmain,panel3,panel4,panel5,panel6,panel7,panelchangepwd,panelchangep wded,panelsave,panelsaved,panelremain,paneltrans,paneltransed,panelmobile,panelmobi led,panelconsult;JButtonbtn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btnsure,btnback,btnok,btnca rd,btngetcard,btnincard;JButtonbtn00,btn01,btn02,btn03,btn04,btn05,btn06,btn07,btn08,btn09,btn010,btnback1,btnrema in,btnremain1,btnremain2;JButtonbtn000,btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn100,btn200 ,btn300,btn1000,btn500,btnsure1,btnback2,btn0010,btnquok1,btnquok2,btnquok3,btnquok 4;JButtonbtnpwd,btnpwd1,btnpwd2,btnpwd3,btnpwd4,btn11,btn12,btn13,btn14,btn15,btn16,btn17,bt n18,btn19,btn20,btnsave,btnsave1,btnsave2,btnsaved,btnsaved1,btnsaved2,btnsaved3;JButtonbtntra,btntra1,btntra2,btntraed,btntraed1,btn21,btn22,btn23,btn24,btn25,btn26,btn27 ,btn28,btn29,btn30,btncon,btncon1;JButtonbtnmo,btnmo1,btnmo2,btnmo30,btnmo50,btnmo100,btnmo200,btnmo500,btnmo10,btnmo11,btnm o12,btnmo13,btnmo14,btnmo15,btnmo16,btnmo17,btnmo18,btnmo19,btnmoed,btnmoed1;JTextField txt2,txttrans,txttrans1,txttrans2,txtmo,txtmo1;JLabellbljixu,lblpwd,lblwrong,lblqukuan,lblquok1,lblquok2,lblpwd1,lblpwd2,lblpwd3,lblpwd4 ,lblsave,lblsave1,lblsaved,lblremain,lblremain1,lbltra,lbltra1,lbltra2,lbltraed,lbl traed1;JLabellblwel,lblwel1,lblmo,lblmo1,lblmo2,lblmo3,lblmoed,lblmoed1,lblcon,lblcon1;JPasswordField txt1,txtpwd,txtpwd1;Container container;CardLayout Layout;int money,savemoney,mobilemoney=0;double lastmoney,trainsmoney;String userpwd,cardnum,trains,username;boolean flag=true,flag1=false,flag2=false,flag3=true,flag4=false,flag5=false;//构造方法public MyATM(){super("罗灿银行");this.setSize(435,350);this.setLocation(500, 250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );//设置不可改变窗口大小this.setResizable(false);//设置程序小图标this.setIconImage(this.getToolkit().getImage("images\\haizei.jpg"));}//布局public void setLayout(){//用卡片布局Layout=new CardLayout();container=getContentPane();container.setLayout(Layout);//添加第一张卡片panelfirst=new JPanel(null);//设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu=new JLabel("请放入磁卡,然后继续操作");//设置卡片在Panel中的位置lbljixu.setBounds(140,90,350,30);//为第一张卡片添加一个Labelpanelfirst.add(lbljixu);//为第一张卡片添加一个按钮btncard=new JButton("继续");btncard.setBounds(310,180,80,30);//为按钮注册事件监听器btncard.addActionListener(this);//开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);//为第一张卡片添加一个按钮btngetcard=new JButton("取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310,220,80,30); btngetcard.addActionListener(this);panelfirst.add(btngetcard);//为第一张卡片添加一个按钮btnincard=new JButton("插卡");btnincard.setBounds(40,220,80,30);btnincard.addActionListener(this);panelfirst.add(btnincard);container.add(panelfirst,"first");//添加登录输入密码卡片panelmain=new JPanel(null);panelmain.setBackground(new Color(119,119,253)); lblpwd=new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(150, 20, 150, 30);//设置文本框为密码型txt1=new JPasswordField(12);//文本框不可选中txt1.enable(false);panelmain.add(txt1);//文本框的输入内容用*显示txt1.setEchoChar('*');txt1.setBounds(115,50,200,30);//添加选择按钮btnsure=new JButton("确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70,160,80,30);//添加重输按钮btn010=new JButton("重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback=new JButton("退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280,160,80,30);lblwrong=new JLabel("请注意保护好您的密码!"); panelmain.add(lblwrong);lblwrong.setBounds(150,90,200,30);//添加输入按钮btn01=new JButton("1");btn01.addActionListener(this);panelmain.add(btn01);btn01.setBounds(45,210,60,30);btn02=new JButton("2");btn02.addActionListener(this);panelmain.add(btn02);btn02.setBounds(115,210,60,30);btn03=new JButton("3");btn03.addActionListener(this);panelmain.add(btn03);btn03.setBounds(185,210,60,30);btn04=new JButton("4");btn04.addActionListener(this);panelmain.add(btn04);btn04.setBounds(255,210,60,30);btn05=new JButton("5");btn05.addActionListener(this);panelmain.add(btn05);btn05.setBounds(325,210,60,30);btn06=new JButton("6");btn06.addActionListener(this);panelmain.add(btn06);btn06.setBounds(45,260,60,30);btn07=new JButton("7");btn07.addActionListener(this);panelmain.add(btn07);btn07.setBounds(115,260,60,30);container.add(panelmain,"main");btn08=new JButton("8");btn08.addActionListener(this);panelmain.add(btn08);btn08.setBounds(185,260,60,30);btn09=new JButton("9");btn09.addActionListener(this);panelmain.add(btn09);btn09.setBounds(255,260,60,30);btn00=new JButton("0");btn00.addActionListener(this);panelmain.add(btn00);btn00.setBounds(325,260,60,30);//添加主界面卡片panel3=new JPanel(null);panel3.setBackground(new Color(119,119,253));lblwel=new JLabel(username+",欢迎使用罗灿银行ATM系统"); lblwel.setBounds(20,15,350,30);panel3.add(lblwel);lblwel1=new JLabel("请选择您需要的交易类型");lblwel1.setBounds(220,55,350,30);panel3.add(lblwel1);btn3=new JButton("取款服务");btn3.addActionListener(this);btn3.setBounds(20,90,100,30);panel3.add(btn3);btn4=new JButton("修改密码");btn4.addActionListener(this);btn4.setBounds(20,150,100,30);panel3.add(btn4);btn5=new JButton("存款服务");btn5.addActionListener(this);btn5.setBounds(20,210,100,30);panel3.add(btn5);btn6=new JButton("查询余额");btn6.addActionListener(this);btn6.setBounds(20,270,100,30);panel3.add(btn6);btn7=new JButton("转账服务");btn7.addActionListener(this);btn7.setBounds(300,90,100,30);panel3.add(btn7);btn8=new JButton("通信交费");btn8.addActionListener(this);btn8.setBounds(300,150,100,30);panel3.add(btn8);btn9=new JButton("咨询服务");btn9.addActionListener(this);btn9.setBounds(300,210,100,30);panel3.add(btn9);btn10=new JButton("退出操作");btn10.addActionListener(this);btn10.setBounds(300,270,100,30);panel3.add(btn10);container.add(panel3,"three");//添加取款页面卡片panel4=new JPanel(null);panel4.setBackground(new Color(119,119,253));lblqukuan=new JLabel("请输入您的取款数:");panel4.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel("提示:只能是100元或100元的整数倍。
ATM自动取款机系统的设计与实现---代码1.实现类//说明:1.管理员登录密码是:luolin//初始用户import java.util.Scanner;public class Achieve {Scanner in = new Scanner(System.in);public void login_interface()//初始界面{System.out.println("\n\n********************** ");System.out.println("** 欢迎进入ATM机**");System.out.println("**********************");System.out.println(" 选择登录方式:");System.out.println(" 1.管理员");System.out.println(" 2.客户");System.out.println(" 3.退出");System.out.println("**********************\n") ;System.out.print("请输入(1~3):");int n = in.nextInt();Bank_Manager bm = new Bank_Manager();User u = new User();switch(n){case 1 :bm.manager_login_passwd();case 2 :u.login();case 3 :System.out.println("本次操作结束!!");break;default: System.out.println("你输入有误,本次操作结束!!");System.exit(0);}}public static void main(String args[]) {Achieve a = new Achieve();a.login_interface();}}2.用户类:import java.util.Iterator;import java.util.Scanner;public class User {Scanner in = new Scanner(System.in);void login()//登录{boolean sign = true;boolean flag = true;Achieve a = new Achieve();System.out.println("请输入帐号:");int n = in.nextInt();System.out.println("请输入密码:");String m = in.next();Iterator<Bank_Manager> iter = Bank_er_list.iterator();while(iter.hasNext()){Bank_Manager b = iter.next();while(b.zhanghao == n && b.passwd.equals(m)){sign = false;if(flag){user_interface(b);}System.out.print("请输入(1~6或其他):");int s = in.nextInt();switch(s){case1 :deposit(b);System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;case2 :draw_money(b);System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;case3 :serch_money(b);System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;case4 :transform_money(b);System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;case5 :alter_passwd(b);System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;case6 :alter_login();System.out.println("\n请按“任意字符+回车”回到登录界面");in.next();user_interface(b);flag=false;continue;default : a.login_interface();}}}if(sign){System.out.println("账号或密码错误,退出主界面。
//初始密码为123456import java.awt。
*;import java。
awt。
event。
*;import javax。
swing。
*;public class MyATM extends JFrame implements ActionListener{ JPanel panelfirst,panelmain,panel3,panel4,panel5,panel6,panel7,panelchangepwd,panelchangepwded,panelsave,panelsaved,panelremain,paneltrans,paneltransed,panelmobile,panelmobiled,panelconsult;JButton btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btnsure,btnback,btnok,btncard,btngetcard,btnincard;JButton btn00,btn01,btn02,btn03,btn04,btn05,btn06,btn07,btn08,btn09,btn010,btnback1,btnremain,btnremain1,btnremain2;JButton btn000,btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn100,btn200,btn300,btn1000,btn500,btnsure1,btnback2,btn0010,btnquok1,btnquok2,btnquok3,btnquok4;JButton btnpwd,btnpwd1,btnpwd2,btnpwd3,btnpwd4,btn11,btn12,btn13,btn14,btn15,btn16,btn17,btn18,btn19,btn20,btnsave,btnsave 1,btnsave2,btnsaved,btnsaved1,btnsaved2,btnsaved3;JButton btntra,btntra1,btntra2,btntraed,btntraed1,btn21,btn22,btn23,btn24,btn25,btn26,btn27,btn28,btn29,btn30,btncon,btncon1;JButton btnmo,btnmo1,btnmo2,btnmo30,btnmo50,btnmo100,btnmo200,btnmo500,btnmo10,btnmo11,btnmo12,btnmo13,btnmo14,btnmo15,btnmo16,btnmo17,btnmo18,btnmo19,btnmoed,btnmoed1;JTextField txt2,txttrans,txttrans1,txttrans2,txtmo,txtmo1;JLabel lbljixu,lblpwd,lblwrong,lblqukuan,lblquok1,lblquok2,lblpwd1,lblpwd2,lblpwd3,lblpwd4,lblsave,lblsave1,lblsaved,lblremain,lblremain1,lbltra,lbltra1,lbltra2,lbltraed,lbltraed1;JLabel lblwel,lblwel1,lblmo,lblmo1,lblmo2,lblmo3,lblmoed,lblmoed1,lblcon,lblcon1;JPasswordField txt1,txtpwd,txtpwd1;Container container;CardLayout Layout;int money,savemoney,mobilemoney=0;double lastmoney,trainsmoney;String userpwd,cardnum,trains,username;boolean flag=true,flag1=false,flag2=false,flag3=true,flag4=false,flag5=false;//构造方法public MyATM(){super("罗灿银行”);this。
import java.util.Scanner;public class Test8_5 {Scanner input=new Scanner(System.in);int pass=123456;double countmoney=10000;double getmoney=0;int change;double allgetmoney=0;public void ATMinputpass(){for (int i = 1; i <=3; i++) {System.out.println("请输入密码:");Int userpass=input.nextInt();If(userpass>=100000&&userpass<=999999){if(userpass==pass){ATMwelcome();}else{System.out.println("您输入的密码有误!");continue;}}else{System.out.println("请重新输入6位密码!");continue;}}System.out.println("对不起!请带上您的有效证件到柜台办理相关手续!");}public void ATMwelcome(){System.out.println("请选择您想要的操作:\n1、取款2、查询\n3、修改密码4、退出");change=input.nextInt();if(change==1){ATMget();}else if(change==2){ATMselect();}else if(change==3){ATMpass();}else if(change==4){ATMexit();}}public void ATMget(){System.out.println("请输入您需要的金额:");getmoney=input.nextDouble();if(countmoney>getmoney){if(getmoney%100==0){if(getmoney<2500){allgetmoney=allgetmoney+getmoney;if(allgetmoney>5000){System.out.println("您今日的交易金额已超5000,无法再次交易!");System.out.println("您是否要继续其他操作!1(继续)/2(退出)");change=input.nextInt();if(change==1){ATMwelcome();}else if(change==2){ATMexit();}}else{countmoney=countmoney-getmoney;System.out.println("交易完成您的余额为:"+countmoney+"元");System.out.println("您是否要继续其他操作!1(继续)/2(退出)");change=input.nextInt();if(change==1){ATMwelcome();}else if(change==2){ATMexit();}}}else{System.out.println("您交易的金额大于2500!不能完成交易!");ATMget();}}else{System.out.println("请输入100的整数!");ATMget();}}else{System.out.println("您的卡上余额不足!不能完成交易!");}}public void ATMselect(){System.out.println("您帐户的余额为:"+countmoney+"元");System.out.println("您是否要进行其他操作1(继续)/2(退出)");change=input.nextInt();if(change==1){ATMwelcome();}else if(change==2){ATMexit();}}public void ATMpass(){System.out.println("请输入您的原始密码:");int userinpass=input.nextInt();if(userinpass==pass){System.out.println("请输入您的新密码:");int newpass1=input.nextInt();System.out.println("请再次输入您的新密码:");int newpass2=input.nextInt();if(newpass1==newpass2){pass=newpass2;System.out.println("修改密码成功!");System.out.println("是否要继续其他操作!1(继续)/2(退出)");change=input.nextInt();if(change==1){ATMwelcome();}else if(change==2){ATMexit();}}else{System.out.println("两次输入的密码不一致!");ATMpass();}}else if(userinpass!=pass){System.out.println("您输入的原始密码有误!感谢您的使用!");ATMinputpass();}}public void ATMexit(){System.out.println("谢谢使用!");ATMinputpass();}}。
JAVA课程设计报告目录1课程设计题目描述和基本设计要求2系统需求分析2.1功能需求分析2.2其他需求分析3系统设计3.1总体设计3.2ATM柜员机界面设计3.3各功能模块设计3.3.1登陆页面模块设计3.3.2选择服务模块设计3.3.3取款模块设计3.3.4退卡模块设计3.4异常处理情况说明4系统实现与测试5总程序6课程设计总结6.1遇到的问题及解决办法6.2心得体会ATM柜员机1课程设计题目描述和基本设计要求ATM柜员机主要是由各个Windows窗口组成,它是由登录页面、选择服务、取款、查询余额、修改密码和退卡等功能。
它的各种按钮的事件和功能可以简单的模拟ATM柜员机的要求。
2系统需求分析2.1功能需求分析主要功能如下所述:要求使用图形用户界面。
当输入给定的卡号和密码(初始卡号为000000和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行:■查询余额:初始余额为50000元•ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支。
■ATM存款:不能出现负存款。
■修改密码:只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。
2.2其他需求分析(1)性能描述实时性好、灵活性强、易于不同年龄阶段的人操作。
(2)设计约束开发工具:JCratorProV3.5.0运行环境:Windows2000以上能实现用户所定义的各项需求。
(3)界面要求以Windows窗口形式显示,标题栏为ATM柜员机名称,右上角有最小化按钮、最大化按钮、关闭按钮,不同的窗口中有不同的按钮和选择菜单。
3系统设计3・1总体设计我所设计的ATM柜员机主要是由登录页面模块还由选择服务模块组成,其中选择服务模块又由取款模块、查询余额模块、修改密码模块、退卡模块组成。
其功能结构图如下所示:图1ATM功能结构示意图3・2ATM柜员机界面设计一个系统界面的好坏直接影响到用户的操作,界面设计要求样式美观、简单明了、方便易操作。
J a v a小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts {protected int id;//银行账号protected String password;//用户密码protected String name;//用户型号protected String personId;//身份账号protected int accountType;//账号类型,0代表储蓄卡,1代表信用卡protected double balance;//账户余额。
之所以定义为protected是让他的子类可以直接用,不需要通过方法来赋值。
protected double ceiling;public String getPassword(){return password;}public void setPassword(String password){this.password=password;}public String getName(){return name;}public void setName(String name){=name;}public String getPersonId(){return personId;}public void setPersonId(String personId){this.personId=personId;}public int getAccountType(){return accountType;}public void setAccountType(int accountType){this.accountType=accountType;}public double getBalance(){return balance;}public void setBalance(double balance){this.balance=balance;}public int getId(){return id;}public void setId(int id){this.id=id;}public double getCeiling(){return ceiling;}public void setCeiling(double ceiling){this.ceiling=ceiling;}//无参数构造方法public accounts(){}//构造方法public accounts(String password,String name,String personId,int accountType, double balance,double ceiling){super();this.password=password;=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}//存款public void deposit(double money){balance+=money;}//取款public void withdraw(double money){if(accountType==1){if((balance+ceiling)<money){对不起,已超出您的信用额度!");}else{balance-=money;}}else{if(balance<money){对不起,账户余额不足!");}else{balance-=money;}}}}DBoper.javapackage DB;import java.sql.*;importimport Account.accounts;public class DBoper {private Connection conn = null;private Statement st = null;private PreparedStatement pstmt = null;private ResultSet rs = null;private ArrayList<accounts> result;//连接数据库public Connection getConnection(){try{Class.forName(conn=}catch(Exception e){数据库连接失败");}return conn;}//修改删除用户数据public boolean accountDataUpdate(String sql){ conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();数据更新成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();更新失败");return false;}}//依据id来修改记录public boolean dataupdateid(accounts user, int id) {conn = getConnection();try {String sql = "update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=? where id="+ id;pstmt = conn.prepareStatement(sql);pstmt.setString(1, user.getName());pstmt.setString(2, user.getPassword());pstmt.setString(3, user.getPersonId());pstmt.setInt(4, user.getAccountType());pstmt.setDouble(5, user.getBalance());pstmt.setDouble(6, user.getCeiling());pstmt.executeUpdate();操作成功");return true;}catch (SQLException e) {e.printStackTrace();操作失败");return false;}}//插入用户数据public boolean accountDataInsert(accounts account){conn=getConnection();try{pstmt=conn.prepareStatement("insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?)");pstmt.setString(1, account.getName());pstmt.setString(2, account.getPassword());pstmt.setString(3, account.getPersonId());pstmt.setInt(4, account.getAccountType());pstmt.setDouble(5, account.getBalance());pstmt.setDouble(6, account.getCeiling());pstmt.executeUpdate();新用户数据插入成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();插入失败");return false;}}//查询数据public ResultSet dataquery(String sql) {conn = getConnection();try {pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();}catch (SQLException e) {e.printStackTrace();检索失败");}return rs;}public ResultSet testlist() {try {String sql = "select * from account where id =1001";pstmt = conn.prepareStatement(sql);sql);rs = pstmt.executeQuery();} catch (SQLException e) {e.printStackTrace();检索失败");}return rs;}public ArrayList<accounts> testt(int id) {ArrayList<accounts> list = new ArrayList<accounts>();conn = getConnection();try {String sql = "select * from account where id=" + id;pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next()) {accounts user = new accounts();user.setName(rs.getString("username"));user.setPassword(rs.getString("userpwd"));user.setPersonId(rs.getString("personId"));user.setAccountType(rs.getInt("accountType"));user.setBalance(rs.getDouble("balance"));user.setCeiling(rs.getDouble("ceiling"));list.add(user);}}catch (SQLException e) {e.printStackTrace();检索失败");}return list;}//根据卡号和密码验证用户是否存在public boolean verify(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();if(rs.next()){return true;}else{return false;}}catch(SQLException e){e.printStackTrace();return false;}}/*** 登录验证*/public accounts verifyAccount(int id, String password) {boolean flag = verify(id, password);if(flag){accounts account=queryByIDandPassword(id, password);return account;}else{用户不存在!");return null;}}//根据卡号和密码查询信息public accounts queryByIDandPassword(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}//根据卡号查询信息public accounts queryByID(int id){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=?");pstmt.setInt(1, id);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}public static void main(String[] args) {// TODO Auto-generated method stubDBoper op=new DBoper();ArrayList<accounts> list=op.testt(1001);for(int i=0;i<list.size();i++){accounts user=new accounts();user=list.get(i);user.getName());user.getPassword());user.getPersonId());user.getAccountType());user.getBalance());user.getCeiling());}}}//图像界面文件夹DN_SYSTEMDefault.java //主界面package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionListener{ accounts account=DN_ATM.client;DBoper db=new DBoper();private JFrame jf;private JButton btn0,btn1,btn2,btn3,btn4,btn5;private Container c;public void defaltDemo() {//添加主界面卡片//DN_ATM.id;int id=DN_ATM.id;//account=db.queryByID(id);jf=new JFrame("DEFAULT");c=jf.getContentPane();c.setLayout(null);c.setBackground(new Color(119,119,253));JLabel lblwel = new JLabel("欢迎"+account.getName()+"用达能银行ATM系统");lblwel.setBounds(20, 15, 350, 30);c.add(lblwel);JLabel lblwel1 = new JLabel("请选择您需要的交易类型");lblwel1.setBounds(120, 45, 350, 30);c.add(lblwel1);btn1 = new JButton("取款服务");btn1.addActionListener(this);btn1.setBounds(70, 90, 100, 30);c.add(btn1);btn2=new JButton("存款服务");btn2.addActionListener(this);btn2.setBounds(210, 90, 100, 30);c.add(btn2);btn3 = new JButton("查询余额");btn3.addActionListener(this);btn3.setBounds(70, 150, 100, 30);c.add(btn3);btn4 = new JButton("转账服务");btn4.addActionListener(this);btn4.setBounds(210, 150, 100, 30);c.add(btn4);btn5 = new JButton("注销账户");btn5.addActionListener(this);btn5.setBounds(70, 210, 100, 30);c.add(btn5);btn0 = new JButton("退出操作");btn0.addActionListener(this);btn0.setBounds(210, 210, 100, 30);c.add(btn0);jf.setVisible(true);jf.setResizable(false);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}//事件处理@Overridepublic void actionPerformed(ActionEvent e){//取款服务if(e.getSource().equals(btn1)){OutMoney outmoney=new OutMoney();outmoney.outMoney();jf.dispose();}//存款服务if(e.getSource().equals(btn2)){InMoney inmoney=new InMoney();inmoney.InMoney();jf.dispose();}//查询余额if(e.getSource().equals(btn3)){GetBalance getbalance=new GetBalance();getbalance.getBalance();jf.dispose();}//转账服务if(e.getSource().equals(btn4)){TransferAccounts tranfer=new TransferAccounts();tranfer.transferAccounts();jf.dispose();}//注销账户if(e.getSource().equals(btn5)){String sql="delete from account where id="+account.getId();boolean flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this,"注销成功!");}else{JOptionPane.showMessageDialog(this, "注销失败!");}}if(e.getSource().equals(btn0)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDefault defaults=new Default();defaults.defaltDemo();}}DN_ATM.java//功能界面package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimportimportimport DB.DBoper;import Account.accounts;public class DN_ATM extends JFrame implements ActionListener{ private JLabel lbljixu;private JButton btngetcard;private JButton btncard,btn010,btn_addAccount,btnsure,btnback;private JTextField txt1;private JPasswordField txt2;private Container container;private CardLayout Layout;private JLabel lblwrong;private JPanel panelfirst,panelmain;public static int id;static accounts client = null;public DN_ATM(){super("达能银行");this.setSize(435, 350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置不可改变窗口大小this.setResizable(false);}//布局public void setLayout(){//用卡片布局Layout = new CardLayout();container = getContentPane();container.setLayout(Layout);//添加第一张卡片panelfirst = new JPanel(null);//设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu = new JLabel("请放入磁卡,然后继续操作");//设置卡片在Panel中的位置lbljixu.setBounds(140, 90, 350, 30);//为第一张卡片添加一个Labelpanelfirst.add(lbljixu);//为第一张卡片添加一个按钮btncard = new JButton("继续");btncard.setBounds(310, 180, 80, 30);//为按钮注册事件监听器btncard.addActionListener(this);//开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);//为第一张卡片添加一个按钮btngetcard = new JButton("取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310, 220, 80, 30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);//添加登录输入卡片panelmain = new JPanel(null);panelmain.setBackground(new Color(119,119,253));//添加登录输入卡号JLabel lblnumber = new JLabel("请输入您的银行卡卡号:"); panelmain.add(lblnumber);lblnumber.setBounds(30, 30, 150, 30);//设置文本框为密码型txt1 = new JTextField(12);//文本框不可选中//txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170, 30, 200, 30);JLabel lblpwd = new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(30, 80, 150, 30);//设置文本框为密码型txt2 = new JPasswordField(12);//文本框不可选中//txt2.enable(false);panelmain.add(txt2);//文本框的输入内容用*显示txt2.setEchoChar('*');txt2.setBounds(170, 80, 200, 30);//添加选择按钮btnsure = new JButton("确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70, 160, 80, 30);//添加重输按钮btn010 = new JButton("重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback = new JButton("退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280, 160, 80, 30);//开户btn_addAccount = new JButton("开户");btn_addAccount.setBounds(70, 220, 80, 30);btn_addAccount.addActionListener(this);panelmain.add(btn_addAccount);lblwrong = new JLabel("请注意保护好您的密码!");panelmain.add(lblwrong);lblwrong.setBounds(180, 110, 200, 30);container.add(panelmain, "main");}//事件处理@SuppressWarnings("deprecation")@Overridepublic void actionPerformed(ActionEvent e){DBoper db=new DBoper();if(e.getSource().equals(btn_addAccount)){OpenAccount open=new OpenAccount();open.adduser();}//磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure)){client = db.verifyAccount(Integer.parseInt(txt1.getText()), txt2.getText());if(client!=null){Default defa=new Default();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText());txt1.setText("");txt2.setText("");}else{lblwrong.setText("卡号或密码不正确,请重新输入!");txt1.setText("");txt2.setText("");}}//重置输入卡号和密码if(e.getSource()==btn010){txt1.setText("");txt2.setText("");lblwrong.setText("请注意保护好您的密码!");}//退出if(e.getSource().equals(btnback)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDN_ATM ATM=new DN_ATM();ATM.setLayout();ATM.setVisible(true);}}GetBalance.java //查询余额package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class GetBalance extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JLabel lblremain1,lblremain;private JButton btnremain,btnremain1;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;//添加查询余额界面卡片public void getBalance(){account=db.queryByID(id);jf=new JFrame("FIND DALANCE");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(new Color(119,119,253));lblremain1 = new JLabel("尊敬的达能用户您好!");lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain = new JLabel("请点击继续操作查询余额:");lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain = new JButton("继续操作");btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1 = new JButton("退出操作");btnremain1.setBounds(200,150,90,30);btnremain1.addActionListener(this);c.add(btnremain1);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){//查询余额if(e.getSource()==btnremain){lblremain1.setText("卡号:"+account.getId()+" 用户名:"+account.getName());lblremain.setText("您的余额为"+account.getBalance()+"元,是否继续操作?");}if(e.getSource()==btnremain1){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubGetBalance balance=new GetBalance();balance.getBalance();}}InMoney.java//存款package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class InMoney extends JFrame implements ActionListener{private JLabel lblsave,lblsave1;private JButton btnsave,btnsave2;private JTextField txt2;private double savemoney ;private double lastmoney;private boolean flag;private JFrame jf;private Container c;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void InMoney(){account=db.queryByID(id);jf=new JFrame("IN MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);//添加存款显示界面卡片c.setBackground(new Color(119,119,253));lblsave = new JLabel("请在存款口处放入存款");lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1 = new JLabel("请注意:只接收100元或100元的整数倍存款");lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2 = new JTextField(12);c.add(txt2);txt2.setBounds(95, 80, 200, 30);btnsave = new JButton("放入存款完毕");btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2 = new JButton("返回");btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btnsave2);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btnsave){savemoney=Double.parseDouble(txt2.getText());lastmoney=account.getBalance();lastmoney+=savemoney;String sql = "update account set balance="+lastmoney+"where id="+ id;flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this, "存款成功!");txt2.setText("");Default defa=new Default();defa.defaltDemo();jf.dispose();}else{JOptionPane.showMessageDialog(this, "存款失败!");}}if(e.getSource()==btnsave2){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubInMoney inmoney=new InMoney();inmoney.InMoney();}}OpenAccount.java //开户package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimportimportimport DB.DBoper;import Account.accounts;public class OpenAccount extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JTextField txtname,txt_personId;private JPasswordField txtpwd,txtpwd1;private JRadioButton rbt1;private JRadioButton rbt2;String accountType;//开户,增加新用户public void adduser(){jf=new JFrame("Open Account");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);JLabel lbname=new JLabel("用户名:");lbname.setBounds(100, 40, 80, 20);txtname=new JTextField();txtname.setBounds(160, 40, 130, 20);c.add(lbname);c.add(txtname);JLabel lbpwd=new JLabel("密码:");lbpwd.setBounds(110, 65, 80, 20);txtpwd=new JPasswordField();txtpwd.setBounds(160, 65, 130, 20);txtpwd.setEchoChar('*');c.add(lbpwd);c.add(txtpwd);JLabel lbpwd1=new JLabel("确认密码:");lbpwd1.setBounds(86, 90, 80, 20);txtpwd1 = new JPasswordField();txtpwd1.setBounds(160, 90, 130, 20);txtpwd1.setEchoChar('*');c.add(lbpwd1);c.add(txtpwd1);JLabel lbpersonId=new JLabel("身份证号:");lbpersonId.setBounds(86, 115, 80, 20);txt_personId = new JTextField();txt_personId.setBounds(160, 115, 130, 20);c.add(lbpersonId);c.add(txt_personId);JLabel lbtype=new JLabel("账户类型:");lbtype.setBounds(86, 120, 80, 60);rbt1=new JRadioButton("信用卡");rbt1.setBounds(160, 135, 70, 30);rbt2=new JRadioButton("储蓄卡");rbt2.setBounds(225, 135, 70, 30);ButtonGroup group=new ButtonGroup();group.add(rbt2);group.add(rbt1);c.add(lbtype);c.add(rbt2);c.add(rbt1);JButton btnsubmit=new JButton("提交");btnsubmit.setBounds(100, 190, 80, 20);JButton btnreset=new JButton("重置");btnreset.setBounds(205, 190, 80, 20);c.add(btnsubmit);c.add(btnreset);btnsubmit.addActionListener(this);btnreset.addActionListener(this);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }public static void main(String[] args) {// TODO Auto-generated method stubOpenAccount openA=new OpenAccount();openA.adduser();}@Overridepublic void actionPerformed(ActionEvent e){accounts account=new accounts();account.setName(txtname.getText());if(txtpwd.getText().equals(txtpwd1.getText())){account.setPassword(txtpwd.getText());}else{JOptionPane.showMessageDialog(this,"两次输入的密码不一致,请重新输入!");}account.setPersonId(txt_personId.getText());if(rbt1.isSelected())accountType="1";if(rbt2.isSelected())accountType="0";account.setAccountType(Integer.parseInt(accountType));account.setBalance(0);if(accountType.equals("1")){account.setCeiling(5000.0);}else{account.setCeiling(0);}DBoper db=new DBoper();if(db.accountDataInsert(account)){JOptionPane.showMessageDialog(this,"开户成功!");jf.dispose();//关闭当前登录窗体return;}else{JOptionPane.showMessageDialog(this,"开户失败!");return;}}}OutMoney.java//取款package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;importimportpublic class OutMoney extends JFrame implements ActionListener{private JFrame jf;private JButton btn100,btn200,btn300,btn500,btn1000;private JButton btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn000;private JButton btnsure1,btn0010,btnback2;private JTextField txt2;private Container c;private JLabel lblqukuan;private int money;private double lastmoney;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void outMoney(){account=db.queryByID(id);jf=new JFrame("OUT MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);//添加取款页面卡片//panel4=new JPanel(null);c.setBackground(new Color(119,119,253));lblqukuan = new JLabel("请输入您的取款金额:");c.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel("提示:只能是100元或100元的整数倍");c.add(lblqukuan);lblqukuan.setBounds(115, 50, 300, 30);txt2 = new JTextField(12);txt2.enable(false);c.add(txt2);txt2.setBounds(115, 90, 200, 30);btn100 = new JButton("100");c.add(btn100);btn200 = new JButton("200");c.add(btn200);btn200.addActionListener(this);btn200.setBounds(115, 190, 60, 30); btn300 = new JButton("300");c.add(btn300);btn300.addActionListener(this);btn300.setBounds(185, 190, 60, 30); btn500 = new JButton("500");btn500=new JButton("500");c.add(btn500);btn500.addActionListener(this);btn500.setBounds(255, 190, 60, 30); btn1000 = new JButton("1000");c.add(btn1000);btn1000.addActionListener(this);btn1000.setBounds(325, 190, 65, 30); btn001 = new JButton("1");c.add(btn001);btn001.addActionListener(this);btn001.setBounds(45, 230, 60, 30); btn002 = new JButton("2");c.add(btn002);btn002.addActionListener(this);btn002.setBounds(115, 230, 60, 30); btn003 = new JButton("3");c.add(btn003);btn003.addActionListener(this);btn003.setBounds(185, 230, 60, 30); btn004 = new JButton("4");c.add(btn004);btn004.addActionListener(this);btn004.setBounds(255, 230, 60, 30); btn005 = new JButton("5");c.add(btn005);btn005.addActionListener(this);btn005.setBounds(325, 230, 65, 30); btn006 = new JButton("6");c.add(btn006);btn006.addActionListener(this);btn006.setBounds(45, 270, 60, 30); btn007 = new JButton("7");c.add(btn007);btn008 = new JButton("8");c.add(btn008);btn008.addActionListener(this);btn008.setBounds(185, 270, 60, 30);btn009 = new JButton("9");c.add(btn009);btn009.addActionListener(this);btn009.setBounds(255, 270, 60, 30);btn000 = new JButton("0");c.add(btn000);btn000.addActionListener(this);btn000.setBounds(325, 270, 65, 30);btnsure1 = new JButton("确定");c.add(btnsure1);btnsure1.addActionListener(this);btnsure1.setBounds(70, 140, 80, 30);btn0010 = new JButton("重输");c.add(btn0010);btn0010.addActionListener(this);btn0010.setBounds(175, 140, 80, 30);btnback2 = new JButton("返回");c.add(btnback2);btnback2.addActionListener(this);btnback2.setBounds(280, 140, 80, 30);jf.setVisible(true);jf.setSize(460,350);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btn000){String a=txt2.getText();if(a.equals("")){txt2.setText("");}else{txt2.setText(a+"0");}}if(e.getSource()==btn001)txt2.setText(txt2.getText()+"1");}if(e.getSource()==btn002){txt2.setText(txt2.getText()+"2");}if(e.getSource()==btn003){ txt2.setText(txt2.getText()+"3"); } if(e.getSource()==btn004){ txt2.setText(txt2.getText()+"4"); } if(e.getSource()==btn005){ txt2.setText(txt2.getText()+"5"); } if(e.getSource()==btn006){ txt2.setText(txt2.getText()+"6"); } if(e.getSource()==btn007){ txt2.setText(txt2.getText()+"7"); } if(e.getSource()==btn008){ txt2.setText(txt2.getText()+"8"); } if(e.getSource()==btn009){ txt2.setText(txt2.getText()+"9"); } if(e.getSource()==btn100){ txt2.setText("100"); }if(e.getSource()==btn200){ txt2.setText("200"); }if(e.getSource()==btn300){ txt2.setText("300"); }if(e.getSource()==btn500){ txt2.setText("500"); }if(e.getSource()==btn1000){ txt2.setText("1000"); }//返回if(e.getSource()==btnback2){Default defa=new Default();defa.defaltDemo();jf.dispose();}//重输if(e.getSource()==btn0010){txt2.setText("");}//取款确定if(e.getSource()==btnsure1)。
原创Java银行账户管理系统代码
简介
本文档将介绍一个原创的Java银行账户管理系统代码。
该代码用于模拟一个简单的银行账户管理系统,包括账户的创建、存款、取款、查询余额等功能。
功能列表
•创建账户:根据用户输入的账户信息,创建新的银行账户。
•存款:将用户输入的金额存入指定账户。
•取款:从指定账户中取出用户指定的金额。
•查询余额:根据用户输入的账户信息,查询指定账户的余额。
开发工具和环境
•开发语言:Java
•开发环境:Eclipse IDE
•JDK版本:Java SE 8
代码实现
下面是代码的具体实现。
```java import java.util.HashMap; import java.util.Map; import java.util.Scanner;
public class BankAccountManagementSystem {
private static Map<String, Double> accountMap = new HashMap<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
System.out.println(\。
Java 小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts {protected int id;// 银行账号protected String password;// 用户密码protected String name;// 用户型号protected String personId;// 身份账号protected int accountType;// 账号类型,0 代表储蓄卡, 1 代表信用卡protected double balance;// 账户余额。
之所以定义为protected 是让他的子类可以直接用,不需要通过方法来赋值。
protected double ceiling;public String getPassword(){return password;}public void setPassword(String password){this.password=password;}public String getName(){return name;}public void setName(String name){=name;}public String getPersonId(){return personId;}public void setPersonId(String personId){this.personId=personId;}public int getAccountType(){return accountType;}public void setAccountType(int accountType){this.accountType=accountType;}public double getBalance(){return balance;}public void setBalance(double balance){this.balance=balance;}public int getId(){return id;}public void setId(int id){this.id=id;}public double getCeiling(){return ceiling;}public void setCeiling(double ceiling){this.ceiling=ceiling;}// 无参数构造方法public accounts(){}// 构造方法public accounts(String password,String name,String personId,int accountType, double balance,double ceiling){super();this.password=password;=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}// 存款public void deposit(double money){balance+=money;}// 取款public void withdraw(double money){if(accountType==1){if((balance+ceiling)<money){System.out.println(" 对不起,已超出您的信用额度!");}else{balance-=money;}}else{if(balance<money){System.out.println(" 对不起,账户余额不足!");}else{balance-=money;}}}}DBoper.javapackage DB;import java.sql.*;import java.util.ArrayList;import Account.accounts;public class DBoper {private Connection conn = null;private Statement st = null;private PreparedStatement pstmt = null;private ResultSet rs = null;private ArrayList<accounts> result;// 连接数据库public Connection getConnection(){try{Class.forName("com.mysql.jdbc.Driver");conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bankmanager?useUnicode=true&characterEncoding=utf8","root","xuewei");}catch(Exception e){System.out.println(" 数据库连接失败");}return conn;}// 修改删除用户数据public boolean accountDataUpdate(String sql){conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();//System.out.println(" 数据更新成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();//System.out.println(" 更新失败");return false;}}// 依据id 来修改记录public boolean dataupdateid(accounts user, int id) {conn = getConnection();try {String sql = "update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=? where id="+ id;pstmt = conn.prepareStatement(sql);pstmt.setString(1, user.getName());pstmt.setString(2, user.getPassword());pstmt.setString(3, user.getPersonId());pstmt.setInt(4, user.getAccountType());pstmt.setDouble(5, user.getBalance());pstmt.setDouble(6, user.getCeiling());pstmt.executeUpdate();System.out.println(" 操作成功");return true;}catch (SQLException e) {e.printStackTrace();System.out.println(" 操作失败");return false;}}// 插入用户数据public boolean accountDataInsert(accounts account){conn=getConnection();try{pstmt=conn.prepareStatement("insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?)");pstmt.setString(1, account.getName());pstmt.setString(2, account.getPassword());pstmt.setString(3, account.getPersonId());pstmt.setInt(4, account.getAccountType());pstmt.setDouble(5, account.getBalance());pstmt.setDouble(6, account.getCeiling());pstmt.executeUpdate();System.out.println(" 新用户数据插入成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();System.out.println(" 插入失败");return false;}}// 查询数据public ResultSet dataquery(String sql) {conn = getConnection();try {pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();}catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return rs;}public ResultSet testlist() {try {String sql = "select * from account where id =1001";pstmt = conn.prepareStatement(sql);System.out.println(sql);rs = pstmt.executeQuery();} catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return rs;}public ArrayList<accounts> testt(int id) {ArrayList<accounts> list = new ArrayList<accounts>();conn = getConnection();try {String sql = "select * from account where id=" + id;pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next()) {accounts user = new accounts();user.setName(rs.getString("username"));user.setPassword(rs.getString("userpwd"));user.setPersonId(rs.getString("personId"));user.setAccountType(rs.getInt("accountType"));user.setBalance(rs.getDouble("balance"));user.setCeiling(rs.getDouble("ceiling"));list.add(user);}}catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return list;}// 根据卡号和密码验证用户是否存在public boolean verify(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();if(rs.next()){return true;}else{return false;}}catch(SQLException e){e.printStackTrace();return false;}}/*** 登录验证*/public accounts verifyAccount(int id, String password) {boolean flag = verify(id, password);if(flag){accounts account=queryByIDandPassword(id, password);return account;}else{System.out.println(" 用户不存在!");return null;}}// 根据卡号和密码查询信息public accounts queryByIDandPassword(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}// 根据卡号查询信息public accounts queryByID(int id){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=?");pstmt.setInt(1, id);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}public static void main(String[] args) {// TODO Auto-generated method stubDBoper op=new DBoper();ArrayList<accounts> list=op.testt(1001);for(int i=0;i<list.size();i++){accounts user=new accounts();user=list.get(i);System.out.println(user.getName());System.out.println(user.getPassword());System.out.println(user.getPersonId());System.out.println(user.getAccountType());System.out.println(user.getBalance());System.out.println(user.getCeiling());}}}// 图像界面文件夹DN_SYSTEMDefault.java // 主界面package DN_SYSTEM;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionListener{accounts account=DN_ATM.client;DBoper db=new DBoper();private JFrame jf;private JButton btn0,btn1,btn2,btn3,btn4,btn5;private Container c;public void defaltDemo() {// 添加主界面卡片//DN_ATM.id;int id=DN_ATM.id;//account=db.queryByID(id);jf=new JFrame("DEFAULT");c=jf.getContentPane();c.setLayout(null);c.setBackground(new Color(119,119,253));JLabel lblwel = new JLabel("欢迎"+account.getName()+" 用达能银行ATM系统");lblwel.setBounds(20, 15, 350, 30);c.add(lblwel);JLabel lblwel1 = new JLabel("请选择您需要的交易类型");lblwel1.setBounds(120, 45, 350, 30);c.add(lblwel1);btn1 = new JButton(" 取款服务");btn1.addActionListener(this);btn1.setBounds(70, 90, 100, 30);c.add(btn1);btn2=new JButton(" 存款服务");btn2.addActionListener(this);btn2.setBounds(210, 90, 100, 30);c.add(btn2);btn3 = new JButton(" 查询余额");btn3.addActionListener(this);btn3.setBounds(70, 150, 100, 30);c.add(btn3);btn4 = new JButton(" 转账服务");btn4.addActionListener(this);btn4.setBounds(210, 150, 100, 30);c.add(btn4);btn5 = new JButton(" 注销账户");btn5.addActionListener(this);btn5.setBounds(70, 210, 100, 30);c.add(btn5);btn0 = new JButton(" 退出操作");btn0.addActionListener(this);btn0.setBounds(210, 210, 100, 30);c.add(btn0);jf.setVisible(true);jf.setResizable(false);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }// 事件处理@Overridepublic void actionPerformed(ActionEvent e){// 取款服务if(e.getSource().equals(btn1)){OutMoney outmoney=new OutMoney();outmoney.outMoney();jf.dispose();}// 存款服务if(e.getSource().equals(btn2)){InMoney inmoney=new InMoney();inmoney.InMoney();jf.dispose();}// 查询余额if(e.getSource().equals(btn3)){GetBalance getbalance=new GetBalance();getbalance.getBalance();jf.dispose();}// 转账服务if(e.getSource().equals(btn4)){TransferAccounts tranfer=new TransferAccounts();tranfer.transferAccounts();jf.dispose();}// 注销账户if(e.getSource().equals(btn5)){String sql="delete from account where id="+account.getId();boolean flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this," 注销成功!");}else{JOptionPane.showMessageDialog(this, " 注销失败!");}}if(e.getSource().equals(btn0)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDefault defaults=new Default();defaults.defaltDemo();}}DN_ATM.java // 功能界面package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.AbstractButton;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import DB.DBoper;import Account.accounts;public class DN_ATM extends JFrame implements ActionListener{ private JLabel lbljixu;private JButton btngetcard;private JButton btncard,btn010,btn_addAccount,btnsure,btnback;private JTextField txt1;private JPasswordField txt2;private Container container;private CardLayout Layout;private JLabel lblwrong;private JPanel panelfirst,panelmain;public static int id;static accounts client = null;public DN_ATM(){super("达能银行");this.setSize(435, 350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置不可改变窗口大小this.setResizable(false);}// 布局public void setLayout(){// 用卡片布局Layout = new CardLayout();container = getContentPane();container.setLayout(Layout);// 添加第一张卡片panelfirst = new JPanel(null);// 设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu = new JLabel(" 请放入磁卡,然后继续操作");// 设置卡片在Panel 中的位置lbljixu.setBounds(140, 90, 350, 30);// 为第一张卡片添加一个Labelpanelfirst.add(lbljixu);// 为第一张卡片添加一个按钮btncard = new JButton(" 继续");btncard.setBounds(310, 180, 80, 30);// 为按钮注册事件监听器btncard.addActionListener(this);// 开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);// 为第一张卡片添加一个按钮btngetcard = new JButton(" 取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310, 220, 80, 30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);// 添加登录输入卡片panelmain = new JPanel(null);panelmain.setBackground(new Color(119,119,253));// 添加登录输入卡号JLabel lblnumber = new JLabel("请输入您的银行卡卡号:"); panelmain.add(lblnumber);lblnumber.setBounds(30, 30, 150, 30);// 设置文本框为密码型txt1 = new JTextField(12);// 文本框不可选中//txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170, 30, 200, 30);JLabel lblpwd = new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(30, 80, 150, 30);// 设置文本框为密码型txt2 = new JPasswordField(12);// 文本框不可选中//txt2.enable(false);panelmain.add(txt2);// 文本框的输入内容用* 显示txt2.setEchoChar('*');txt2.setBounds(170, 80, 200, 30);// 添加选择按钮btnsure = new JButton(" 确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70, 160, 80, 30);// 添加重输按钮btn010 = new JButton(" 重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback = new JButton(" 退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280, 160, 80, 30);// 开户btn_addAccount = new JButton(" 开户");btn_addAccount.setBounds(70, 220, 80, 30);btn_addAccount.addActionListener(this);panelmain.add(btn_addAccount);lblwrong = new JLabel(" 请注意保护好您的密码!");panelmain.add(lblwrong);lblwrong.setBounds(180, 110, 200, 30);container.add(panelmain, "main");}// 事件处理@SuppressWarnings("deprecation")@Overridepublic void actionPerformed(ActionEvent e){DBoper db=new DBoper();if(e.getSource().equals(btn_addAccount)){OpenAccount open=new OpenAccount();open.adduser();}// 磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure)){client = db.verifyAccount(Integer.parseInt(txt1.getText()), txt2.getText());if(client!=null){Default defa=new Default();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText());txt1.setText("");txt2.setText("");}else{lblwrong.setText(" 卡号或密码不正确,请重新输入!");txt1.setText("");txt2.setText("");}}// 重置输入卡号和密码if(e.getSource()==btn010){txt1.setText("");txt2.setText("");lblwrong.setText(" 请注意保护好您的密码!");}// 退出if(e.getSource().equals(btnback)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDN_ATM ATM=new DN_ATM();ATM.setLayout();ATM.setVisible(true);}}GetBalance.java // 查询余额package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class GetBalance extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JLabel lblremain1,lblremain;private JButton btnremain,btnremain1;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;// 添加查询余额界面卡片public void getBalance(){account=db.queryByID(id);jf=new JFrame("FIND DALANCE");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(new Color(119,119,253));lblremain1 = new JLabel(" 尊敬的达能用户您好!");lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain = new JLabel(" 请点击继续操作查询余额:");lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain = new JButton(" 继续操作");btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1 = new JButton(" 退出操作");btnremain1.setBounds(200,150,90,30);btnremain1.addActionListener(this);c.add(btnremain1);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){// 查询余额if(e.getSource()==btnremain){lblremain1.setText(" 卡号:"+account.getId()+" 用户名:"+account.getName());lblremain.setText(" 您的余额为"+account.getBalance()+" 元,是否继续操作?");}if(e.getSource()==btnremain1){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubGetBalance balance=new GetBalance();balance.getBalance();}}InMoney.java // 存款package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class InMoney extends JFrame implements ActionListener{private JLabel lblsave,lblsave1;private JButton btnsave,btnsave2;private JTextField txt2;private double savemoney ;private double lastmoney;private boolean flag;private JFrame jf;private Container c;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void InMoney(){account=db.queryByID(id);jf=new JFrame("IN MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);// 添加存款显示界面卡片c.setBackground(new Color(119,119,253));lblsave = new JLabel("请在存款口处放入存款");lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1 = new JLabel("请注意:只接收100 元或100 元的整数倍存款");lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2 = new JTextField(12);c.add(txt2);txt2.setBounds(95, 80, 200, 30);btnsave = new JButton(" 放入存款完毕");btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2 = new JButton(" 返回");btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btnsave2);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btnsave){savemoney=Double.parseDouble(txt2.getText());lastmoney=account.getBalance();lastmoney+=savemoney;String sql = "update account set balance="+lastmoney+"where id="+ id;flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this, " 存款成功!");txt2.setText("");Default defa=new Default();defa.defaltDemo();jf.dispose();}else{JOptionPane.showMessageDialog(this, " 存款失败!");}}if(e.getSource()==btnsave2){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubInMoney inmoney=new InMoney();inmoney.InMoney();}}OpenAccount.java // 开户package DN_SYSTEM;import ponent;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.WindowConstants;import DB.DBoper;import Account.accounts;public class OpenAccount extends JFrame implements ActionListener{private JFrame jf;private Container c;private JTextField txtname,txt_personId;private JPasswordField txtpwd,txtpwd1;private JRadioButton rbt1;private JRadioButton rbt2;String accountType;// 开户,增加新用户public void adduser(){jf=new JFrame("Open Account");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);JLabel lbname=new JLabel("用户名:");lbname.setBounds(100, 40, 80, 20);txtname=new JTextField();txtname.setBounds(160, 40, 130, 20);c.add(lbname);c.add(txtname);JLabel lbpwd=new JLabel("密码:");lbpwd.setBounds(110, 65, 80, 20);txtpwd=new JPasswordField();txtpwd.setBounds(160, 65, 130, 20);txtpwd.setEchoChar('*');c.add(lbpwd);c.add(txtpwd);JLabel lbpwd1=new JLabel("确认密码:");lbpwd1.setBounds(86, 90, 80, 20);txtpwd1 = new JPasswordField();txtpwd1.setBounds(160, 90, 130, 20);txtpwd1.setEchoChar('*');c.add(lbpwd1);c.add(txtpwd1);JLabel lbpersonId=new JLabel("身份证号:");lbpersonId.setBounds(86, 115, 80, 20);txt_personId = new JTextField();txt_personId.setBounds(160, 115, 130, 20);c.add(lbpersonId);c.add(txt_personId);JLabel lbtype=new JLabel("账户类型:");lbtype.setBounds(86, 120, 80, 60);rbt1=new JRadioButton(" 信用卡");rbt1.setBounds(160, 135, 70, 30);rbt2=new JRadioButton(" 储蓄卡");rbt2.setBounds(225, 135, 70, 30);ButtonGroup group=new ButtonGroup();group.add(rbt2);group.add(rbt1);c.add(lbtype);c.add(rbt2);c.add(rbt1);JButton btnsubmit=new JButton(" 提交");btnsubmit.setBounds(100, 190, 80, 20);JButton btnreset=new JButton(" 重置");btnreset.setBounds(205, 190, 80, 20);c.add(btnsubmit);c.add(btnreset);btnsubmit.addActionListener(this);btnreset.addActionListener(this);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }public static void main(String[] args) {// TODO Auto-generated method stubOpenAccount openA=new OpenAccount();openA.adduser();}@Overridepublic void actionPerformed(ActionEvent e){accounts account=new accounts();account.setName(txtname.getText());if(txtpwd.getText().equals(txtpwd1.getText())){account.setPassword(txtpwd.getText());}else{JOptionPane.showMessageDialog(this," 两次输入的密码不一致,请重新输入!");}account.setPersonId(txt_personId.getText());if(rbt1.isSelected())accountType="1";if(rbt2.isSelected())accountType="0";account.setAccountType(Integer.parseInt(accountType));account.setBalance(0);if(accountType.equals("1")){account.setCeiling(5000.0);}else{account.setCeiling(0);}DBoper db=new DBoper();if(db.accountDataInsert(account)){JOptionPane.showMessageDialog(this," 开户成功!");jf.dispose();// 关闭当前登录窗体return;}else{JOptionPane.showMessageDialog(this," 开户失败!");return;}}}OutMoney.java // 取款package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class OutMoney extends JFrame implements ActionListener{private JFrame jf;private JButton btn100,btn200,btn300,btn500,btn1000;private JButton btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn000;private JButton btnsure1,btn0010,btnback2;private JTextField txt2;private Container c;private JLabel lblqukuan;private int money;private double lastmoney;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void outMoney(){account=db.queryByID(id);jf=new JFrame("OUT MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);// 添加取款页面卡片//panel4=new JPanel(null);c.setBackground(new Color(119,119,253));lblqukuan = new JLabel(" 请输入您的取款金额:");c.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel(" 提示:只能是100 元或100 元的整数倍");c.add(lblqukuan);lblqukuan.setBounds(115, 50, 300, 30);txt2 = new JTextField(12);txt2.enable(false);c.add(txt2);txt2.setBounds(115, 90, 200, 30);btn100 = new JButton("100");c.add(btn100);btn100.addActionListener(this);btn100.setBounds(45, 190, 60, 30);btn200 = new JButton("200");c.add(btn200);btn200.addActionListener(this);btn200.setBounds(115, 190, 60, 30);btn300 = new JButton("300");c.add(btn300);btn300.addActionListener(this);btn300.setBounds(185, 190, 60, 30);btn500 = new JButton("500");btn500=new JButton("500");c.add(btn500);btn500.addActionListener(this);btn500.setBounds(255, 190, 60, 30);btn1000 = new JButton("1000");c.add(btn1000);btn1000.addActionListener(this);btn1000.setBounds(325, 190, 65, 30);btn001 = new JButton("1");c.add(btn001);btn001.addActionListener(this);btn001.setBounds(45, 230, 60, 30);btn002 = new JButton("2");c.add(btn002);btn002.addActionListener(this); btn002.setBounds(115, 230, 60, 30);btn003 = new JButton("3");c.add(btn003);btn003.addActionListener(this); btn003.setBounds(185, 230, 60, 30);btn004 = new JButton("4");c.add(btn004);btn004.addActionListener(this); btn004.setBounds(255, 230, 60, 30);btn005 = new JButton("5");c.add(btn005);btn005.addActionListener(this); btn005.setBounds(325, 230, 65, 30);btn006 = new JButton("6");c.add(btn006);btn006.addActionListener(this); btn006.setBounds(45, 270, 60, 30);btn007 = new JButton("7");c.add(btn007);btn007.addActionListener(this); btn007.setBounds(115, 270, 60, 30);btn008 = new JButton("8");c.add(btn008);btn008.addActionListener(this); btn008.setBounds(185, 270, 60, 30);btn009 = new JButton("9");c.add(btn009);btn009.addActionListener(this); btn009.setBounds(255, 270, 60, 30);btn000 = new JButton("0");c.add(btn000);btn000.addActionListener(this); btn000.setBounds(325, 270, 65, 30);btnsure1 = new JButton(" 确定");。
//初始密码为123456import java.awt.*;import java.awt.event.*;import javax.swing.*;public class MyATM extends JFrame implements ActionListener{ JPanelpanelfirst,panelmain,panel3,panel4,panel5,panel6,panel7,panelchangepw d,panelchangepwded,panelsave,panelsaved,panelremain,paneltrans,panelt ransed,panelmobile,panelmobiled,panelconsult;JButtonbtn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btnsure,btnba ck,btnok,btncard,btngetcard,btnincard;JButtonbtn00,btn01,btn02,btn03,btn04,btn05,btn06,btn07,btn08,btn09,btn010,bt nback1,btnremain,btnremain1,btnremain2;JButtonbtn000,btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009 ,btn100,btn200,btn300,btn1000,btn500,btnsure1,btnback2,btn0010,btnquo k1,btnquok2,btnquok3,btnquok4;JButtonbtnpwd,btnpwd1,btnpwd2,btnpwd3,btnpwd4,btn11,btn12,btn13,btn14,btn15, btn16,btn17,btn18,btn19,btn20,btnsave,btnsave1,btnsave2,btnsaved,btns aved1,btnsaved2,btnsaved3;JButtonbtntra,btntra1,btntra2,btntraed,btntraed1,btn21,btn22,btn23,btn24,btn 25,btn26,btn27,btn28,btn29,btn30,btncon,btncon1;JButtonbtnmo,btnmo1,btnmo2,btnmo30,btnmo50,btnmo100,btnmo200,btnmo500,btnmo1 0,btnmo11,btnmo12,btnmo13,btnmo14,btnmo15,btnmo16,btnmo17,btnmo18,btn mo19,btnmoed,btnmoed1;JTextField txt2,txttrans,txttrans1,txttrans2,txtmo,txtmo1;JLabellbljixu,lblpwd,lblwrong,lblqukuan,lblquok1,lblquok2,lblpwd1,lblpwd2,l blpwd3,lblpwd4,lblsave,lblsave1,lblsaved,lblremain,lblremain1,lbltra, lbltra1,lbltra2,lbltraed,lbltraed1;JLabellblwel,lblwel1,lblmo,lblmo1,lblmo2,lblmo3,lblmoed,lblmoed1,lblcon,lbl con1;JPasswordField txt1,txtpwd,txtpwd1;Container container;CardLayout Layout;int money,savemoney,mobilemoney=0;double lastmoney,trainsmoney;String userpwd,cardnum,trains,username;booleanflag=true,flag1=false,flag2=false,flag3=true,flag4=false,flag5=false;//构造方法public MyATM(){super("罗灿银行");this.setSize(435,350);this.setLocation(500, 250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );//设置不可改变窗口大小this.setResizable(false);//设置程序小图标this.setIconImage(this.getToolkit().getImage("images\\haizei.jpg" ));}//布局public void setLayout(){//用卡片布局Layout=new CardLayout();container=getContentPane();container.setLayout(Layout);//添加第一张卡片panelfirst=new JPanel(null);//设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu=new JLabel("请放入磁卡,然后继续操作");//设置卡片在Panel中的位置lbljixu.setBounds(140,90,350,30);//为第一张卡片添加一个Labelpanelfirst.add(lbljixu);//为第一张卡片添加一个按钮btncard=new JButton("继续");btncard.setBounds(310,180,80,30);//为按钮注册事件监听器btncard.addActionListener(this);//开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);//为第一张卡片添加一个按钮btngetcard=new JButton("取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310,220,80,30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);//为第一张卡片添加一个按钮btnincard=new JButton("插卡");btnincard.setBounds(40,220,80,30);btnincard.addActionListener(this);panelfirst.add(btnincard);container.add(panelfirst,"first");//添加登录输入密码卡片panelmain=new JPanel(null);panelmain.setBackground(new Color(119,119,253)); lblpwd=new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(150, 20, 150, 30);//设置文本框为密码型txt1=new JPasswordField(12);//文本框不可选中txt1.enable(false);panelmain.add(txt1);//文本框的输入内容用*显示txt1.setEchoChar('*');txt1.setBounds(115,50,200,30);//添加选择按钮btnsure=new JButton("确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70,160,80,30);//添加重输按钮btn010=new JButton("重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback=new JButton("退出");btnback.addActionListener(this); panelmain.add(btnback);btnback.setBounds(280,160,80,30);lblwrong=new JLabel("请注意保护好您的密码!"); panelmain.add(lblwrong);lblwrong.setBounds(150,90,200,30);//添加输入按钮btn01=new JButton("1");btn01.addActionListener(this);panelmain.add(btn01);btn01.setBounds(45,210,60,30);btn02=new JButton("2");btn02.addActionListener(this);panelmain.add(btn02);btn02.setBounds(115,210,60,30);btn03=new JButton("3");btn03.addActionListener(this);panelmain.add(btn03);btn03.setBounds(185,210,60,30);btn04=new JButton("4");btn04.addActionListener(this);panelmain.add(btn04);btn04.setBounds(255,210,60,30);btn05=new JButton("5");btn05.addActionListener(this);panelmain.add(btn05);btn05.setBounds(325,210,60,30);btn06=new JButton("6");btn06.addActionListener(this);panelmain.add(btn06);btn06.setBounds(45,260,60,30);btn07=new JButton("7");btn07.addActionListener(this);panelmain.add(btn07);btn07.setBounds(115,260,60,30);container.add(panelmain,"main");btn08=new JButton("8");btn08.addActionListener(this);panelmain.add(btn08);btn08.setBounds(185,260,60,30);btn09=new JButton("9");btn09.addActionListener(this);panelmain.add(btn09);btn09.setBounds(255,260,60,30);btn00=new JButton("0");btn00.addActionListener(this);panelmain.add(btn00);btn00.setBounds(325,260,60,30);//添加主界面卡片panel3=new JPanel(null);panel3.setBackground(new Color(119,119,253));lblwel=new JLabel(username+",欢迎使用罗灿银行ATM系统"); lblwel.setBounds(20,15,350,30);panel3.add(lblwel);lblwel1=new JLabel("请选择您需要的交易类型");lblwel1.setBounds(220,55,350,30);panel3.add(lblwel1);btn3=new JButton("取款服务");btn3.addActionListener(this);btn3.setBounds(20,90,100,30);panel3.add(btn3);btn4=new JButton("修改密码");btn4.addActionListener(this);btn4.setBounds(20,150,100,30);panel3.add(btn4);btn5=new JButton("存款服务");btn5.addActionListener(this);btn5.setBounds(20,210,100,30);panel3.add(btn5);btn6=new JButton("查询余额");btn6.addActionListener(this);btn6.setBounds(20,270,100,30);panel3.add(btn6);btn7=new JButton("转账服务");btn7.addActionListener(this);btn7.setBounds(300,90,100,30);panel3.add(btn7);btn8=new JButton("通信交费");btn8.addActionListener(this);btn8.setBounds(300,150,100,30);panel3.add(btn8);btn9=new JButton("咨询服务");btn9.addActionListener(this);btn9.setBounds(300,210,100,30);panel3.add(btn9);btn10=new JButton("退出操作");btn10.addActionListener(this);btn10.setBounds(300,270,100,30);panel3.add(btn10);container.add(panel3,"three");//添加取款页面卡片panel4=new JPanel(null);panel4.setBackground(new Color(119,119,253));lblqukuan=new JLabel("请输入您的取款数:");panel4.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel("提示:只能是100元或100元的整数倍。