小程序教程

java课程设计-ATM柜员机模拟程序

字号+ 作者:H5之家 来源:H5之家 2017-09-01 18:05 我要评论( )

课程设计(大作业)报告课程名称:面向对象程序设计课程设计 设计题目:ATM 柜员机模拟程序 院 班 系:信息技术学院 级:设 计 者: 学 号:指导教师: 设计时间


课程设计(大作业)报告

课程名称:面向对象程序设计课程设计 设计题目:ATM 柜员机模拟程序 院 班 系:信息技术学院 级:

设 计 者: 学 号:

指导教师: 设计时间:2016-1-4-2016-1-8












昆明学院课程设计(大作业)任务书
姓 名: 院(系) :信息技术学院 专 业:计算机科学与技术 学 号: 任务起止日期:2016-1-4-2016-1-8 课程设计题目: 设计一个 ATM 柜员机模拟程序,实现系统登录、余额查询、ATM 取款、ATM 存款、修改密 码等一些 ATM 柜员机的基本功能,模拟 ATM 的工作原理和人机交互。 课程设计要求: 使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码为 123456)时,系统 能登录 ATM 柜员机系统,用户可以按照以下规则进行: 1、查询余额:初始余额为 10000 元 2、ATM 取款:每次取款金额为 100 的倍数,总额不超过 5000 元,支取金额不允许透支。 3、ATM 存款:不能出现负存款。 4、修改密码:新密码长度不小于 6 位,不允许出现 6 位完全相同的情况,只有旧密码正确, 新密码符合要求,且两次输入相同的情况下才可以成功修改密码。 工作计划及安排: 1 月 4 号,老师布置任务、讲授设计内容。 1 月 5 号,查阅资料,进行初步设想并画出流程图。 1 月 6 号,详细设计,创建各个类、编写程序代码。 1 月 7 号,测试,对程序进行调试、运行并进行相应的分析。 1 月 8 号,书写课程设计报告,验收、考核及答辩。

指导教师签字 年 月 日

课程设计(大作业)成绩
学号: 姓名: 指导教师:

课程设计题目: 设计一个 ATM 柜员机模拟程序,实现系统登录、余额查询、ATM 取款、ATM 存款、修改 密码等一些 ATM 柜员机的基本功能,模拟 ATM 的工作原理和人机交互。
总结:

通过为时一周的课程设计,我受益匪浅,把平时所学的知识通通运用了进来,虽然平时 积淀的知识点比较少、比较单一,但是在这次实验中把零零碎碎的知识都连贯起来了,也达 到了课程设计的目的, 最主要的是通过一周的努力我终于用面向对象程序设计的知识做出了 这个“ATM 柜员机模拟系统” 。由于知识的积淀比较少,且有些知识掌握不太牢靠,记忆模 模糊糊的,最后决定恶补一下落下的知识点再进行程序的设计。第一天,去图书馆借了相关 图书,把知识点打牢,然后参考了相似的的几个实例,并进行了一些分析和总结。基础功课 做好以后第二天正式开工,选定好了题目,进行方法选择、框架设计、画出流程图、UML 图,进行了初步的程序设计构想。第三天,编写程序代码,这个过程我觉得是最艰难的,因 为代码太多,还有 API 接口不是很熟悉,所以要经常翻阅手册,花费了很多时间。程序一 不小心就会出错不能运行,还需要认真检查,细心细心加细心才能做好。反复的进行分析调 试,最后一天把程序调试通过后,进行课程设计报告的撰写。虽然很幸苦但是,最终的成果 还是令人满意的,最后感谢指导老师对我们帮助和支持。

指导教师评语:

成绩:

填表时间:

指导教师签名:

课程设计(大作业)报告
一、 题目分析
1.系统需求分析
(1)设计目标:随着市场经济的繁荣发展,人们的物质生活得到极大的提高,手中的 剩余资金也日益增多。受传统观念影响,绝大多数人喜欢把资金投进银行,而在需要使用现 金的时候再到银行提取现金。这就导致银行业务的急剧增加。虽然银行网点越来越多,银行 的工作效率也随着信息化有较明显的增长, 但是依旧不能满足广大用户的需要。 而一味的增 加营业网点,从理论上虽然能稍微的缓解银行的压力,但是治标不治本,而且每增加一个网 点,不仅要付出昂贵的资金成本,还需要长期投入人力资本,成本非常之昂贵。这时候就迫 切的需要一种自动的,易于普及的,低成本的设备来解决这一问题。于是 ATM 机系统应运而 生了。 自动柜员机,即 ATM,是指银行在不同地点设置一种小型机器,利用一张信用卡大小的 胶卡上的磁带记录客户的基本户口资料 (通常就是银行卡) , 让客户可以透过机器进行提款、 存款、转账等银行柜台服务,大多数客户都把这种自助机器称为自动提款机。 本文正是通过设计一个 ATM 模拟模拟程序来实现 ATM 机系统的基本功能, 充分运用自己 所学的 Java 知识进行设计编程。 (2)题目设计要求:本 ATM 柜员机的主要功能如下所述: 要求使用图形用户界面。当输入给定的卡号和密码(初始卡号和密码为 123456)时, 系统能登录 ATM 柜员机系统,用户可以按照以下规则进行: ? ? 查询余额:初始余额为 10000 元。 ATM 取款:每次取款金额为 100 的倍数,总额不超过 5000 元,支取金额不允许透 支。 ? ? ATM 存款:不能出现负存款。 修改密码:新密码长度不小于 6 位,不允许出现 6 位完全相同的情况,只有旧密 码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码。

2.ATM 模拟系统总体设计结构
(1)设计思想:通过程序要求,我们可以清楚的知道本次设计的 ATM 柜员模拟程序需

要实现四大功能,即查询余额、取款、存款、修改密码。初次之外,作为 ATM 系统,还需要 最基本的两大功能,即登陆和退出。 根据上述的功能分析,我们可以把整个 ATM 系统分为登陆模块、查询模块、取款模块、 存款模块、修改密码模块。除此之外,还有在登陆系统后的功能选择模块,退出功能则镶嵌 在各个需要的模块中。 由于各个模块的功能实现是通过界面显示出来的, 则程序设计又可以 理解为几大界面的设计:登陆界面、主界面、查询余额界面、取款界面、存款界面、修改密 码界面。除了几大界面之外,还有系统的初始化,主要是初始卡号、密码的设定等。 在程序的大体框架确定之后, 我们需要了解各个模块所要实现和需要具有的功能。 根据 现有的银行 ATM 系统,我们可以很快就可以了解本次设计的 ATM 系统应该具有的操作。 a.登陆界面 用户输入正确的账号和密码就可以登录到该系统的主界面中去, 进行相应的操作: 取款、 存款、查询、修改密码。 b.主界面 主界面包括查询、存款、取款、修改密码、退出的功能按钮,按下相应的按钮,可以进 行相应的操作。 c.查询界面 在主界面中按下查询按钮可以进行查询操作。通过查询功能我们可以查询账户的余额, 在查询过程中我们可以选择取款的业务,除此之外,查询界面之中还有返回和退出的操作。 返回的操作会使用户回到主界面,退出的操作会使用户直接回到登陆界面。 d.取款界面 取款界面既可以通过主界面进入,也可以通过查询、存款等操作过程中的界面进入。取 款功能在对话框中输入你想要取出的金额,但是次金额不可以比账户的余额大,且必须是 100 的整数倍,取款完毕,会弹出是否显示余额的提示,选“是”的话就会进入查询界面, 选“否”的话,则回到主界面。 e.存款界面 在主界面按下存款按钮可以进行存款操作, 在对话中输入你需要存入的金额, 所输入的 数字也要是 100 的整数倍,而且不可以是负数。存款完毕,会弹出是否显示余额的提示,选 “是”的话就会进入查询界面,选“否”的话,则回到主界面。 f.修改密码 选择修改密码按钮可以进行修改密码房, 但是要先输入就密码正确并且两次输入新密码

一致才可以修改密码。修改完成后,会返回主界面。 (2)ATM 柜员机总体流程图,如图 图 1
登录

输入账号和密码 N 账号和密码 是否正确 Y 主界面

选择业务

查 询

存 款

取 款

修 改 密 码

退 出

显 示 余 额 Y

存入

取款

输入密码

Y

N 显示 余额 是否 符合

返 回

退 出

取 款

显示 余额 N

N

Y

图1

(3)ATM 柜员机模拟模拟系统 UML 图,如图 图 2

图 2

3.系统开发及运行环境
软件平台:Eclipse,jdk 全套软件,editpuls 编辑器 Eclipse 是一个开放源代码的、基于 Java 的可扩展开发平台。就其本身而言,它只是一 个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准 的插件集,包括 Java 开发工具(Java Development Kit,JDK) 。Eclipse 是著名的跨平台的自 由集成开发环境(IDE) 。最初主要用来 Java 语言开发,通过安装不同的插件 Eclipse 可以支 持不同的计算机语言,比如 C++和 Python 等开发工具。Eclipse 的本身只是一个框架平台, 但是众多插件的支持使得 Eclipse 拥有其他功能相对固定的 IDE 软件很难具有的灵活性。许 多软件开发商以 Eclipse 为框架开发自己的 IDE。

图 3

二、各模块分析与实现
1.系统各模块介绍
代码中出现的 Account 类、MainFrame 类、Load 类、Take 类、Input 类、Setpew 类和 Display 类都继承了 Java 类 JFrame。 (1)账户创建模块 Class Accout 创建客户,初始化客户信息功能以及保存客户信息,例如:卡号、密码、 原有余额、 取款后卡里的余额以及存款后卡里的余额。 此类包含的成员有: 成员变量 account、 count、password 和方法构造方法 Account()。实现了账户信息的初始化工作,设置默认账户 信息,账号:123456,密码:123456。以便后续测试登陆时作为进入ATM模拟系统的信息 凭证。

创建账户关键代码:
class Account { private int count=10000; private String account="123456"; private String password="123456"; public Account() { } public void setpw(String password){ this.password=password; } public void deccount(int money){ } public void reccount(int money){ } //reccount 存款 count+=money;//存款后在原来基础上加所存部分 //deccount 取款 count-=money;//取款后再原来基础上减所取部分 //设置密码 //账户函数 //初始账户余额 10000 //初始账号 //初始密码

(2)主界面构造模块 Class MainFrame 构造主界面,提供业务选择,让用户可以在这个界面选择存款、取款、 查询余额、修改密码。它包含的成员有:构造方法 MainFrame()和初始化主界面的方法 initComponents()以及成员变量 checked、cunkuan、quite、qukuan、reset。实现的功能主要为 主界面的初始化,主界面的布局管理,设置好查询、存款、取款、退出、返回的操作按钮。 关键代码:class MainFrame extends JFrame { //主框架方法由 JFrame 继承而来
public JButton checked; public JButton cunkuan; public JButton quit; public JButton qukuan; public JButton reset; public MainFrame() { initComponents(); //检测 //存款 //退出 //取款 //重设 //框架按钮参数 //主框架函数 //添加组件

this.setLocationRelativeTo(null); //设置窗口相对于指定组件的位置 this.setVisible(false); //隐藏其他窗口 }

(3)登陆模块 Class Load 实现登录功能和登录界面, 如果用户名和密码匹配就可以登录到主界面否则 报错。它的成员有:Jpassword、accountnum、committ、JL1、JL2 和构造方法 Load()和初始 化方法 initComponents()。 关键代码:class Load extends JFrame{
public JPasswordField Jpassword;

public JTextField accountnum;// public JButton commit;//增删 private JLabel jL1;//设置对齐 private JLabel jL2; public Load() { initComponents(); this.setVisible(true); } //初始化添加组件的和添加监听器 this.setLocationRelativeTo(null);//使窗口至于屏幕中央

(4)取款模块 Class Take 实现取款功能,按返回键返回主界面,按清除键可以删除输入数字,并且取 出的金额必须是 100 的整数倍,一次取出的金额不能超过 5000,取完款后可以显示余额。 该类的成员有:back、clear、commit、quite、JL1、JT1 和构造方法 Take()和初始化的 initComponents()。 关键代码:class Take extends JFrame {
public JButton back; public JButton clear; public JButton commit; private JLabel jL1; public JTextField jT1; public JButton quit; String str=""; public Take() { initComponents(); this.setLocationRelativeTo(null); this.setVisible(false); }

(5)存款模块 Class input 实现存款功能,存款的金额必须是 100 的整数倍,否则报错提示重新输入。 成员有: clear、 commit、 jL1、 jT1、 str 以及构造函数 Inputhe () 和初始化方法 initComponents()。 关键代码:class Input extends JFrame {
private JButton clear; private JButton commit; private JLabel jL1; private JTextField jT1; String str=""; public Input() { initComponents(); this.setLocationRelativeTo(null); this.setResizable(false);

this.setVisible(false); }

(6)显示余额模块 Class Display 功能为显示当前余额,在显示余额时 JTextField 的内容不可以编辑,成员 有:成员变量 back、jL1、quit、qukuan 和构造方法 Display()和方法数 set(String str)和初始化 的方法 initComponents()。 关键代码:class Display extends JFrame {
public JButton back; private JLabel jL1; public JTextField jT1; public JButton quit; public JButton qukuan; public Display() { initComponents(); jT1.setText(String.valueOf(myaccount.get())); this.setLocationRelativeTo(null); this.setVisible(false);

} (7)修改密码模块 class Setpw 创建此类是为了实现修改密码的功能,设置的密码必须是六位以上的字符, 并且所设置的密码不能是同一个字符组成, 否则报错。 成员有: 成员变量 commit、 commitpw、 jPwcommit、jPwnew、jPwold、newpw、oldpw、quit 和构造方法 Setpw()和初始化方法 initComponents()。 关键代码:class Setpw extends JFrame {
public JButton commit; public JLabel commitpw; public JPasswordField jPwcommit; public JPasswordField jPwnew; public JPasswordField jPwold; public JLabel newpw; public JLabel oldpw; public JButton quit; public Setpw() { initComponents(); this.setResizable(false); this.setLocationRelativeTo(null); this.setVisible(false);

}

2.事件监听组件介绍
(1) MainFrame 类的监听模块 在该类中设置了五个监听器,监听鼠标单击按钮,分别监听退出 quit.addActionListener(new ActionListener()、 修改密码 reset.addActionListener(new ActionListener()、查询 checked.addActionListener(new ActionListener()、取款 cunkuan.addActionListener(new ActionListener()、 存款 qukuan.addActionListener(new ActionListener()等按钮的事件。 (2) Load 类的监模块 commit.addActionListener(new java.awt.event.ActionListener() 在该类中只有一个监听器,监听鼠标单击“确定”按钮时的事件。 (3) Take 类的监听模块 在该类中设置了四个监听器,同样是监听鼠标单击按钮事件,分别监听“清除” clear.addActionListener(new ActionListener()、 “退出” quit.addActionListener(new ActionListener()、 “返回” back.addActionListener(new ActionListener()、 “确定” commit.addActionListener(new ActionListener()按钮的事件。 (4 )input 类的监模块 在这个类中共设置了两个监听器,它们也是监听鼠标单击按钮事件。它们监听“清除” clear.addActionListener(new ActionListener()、 “确定” commit.addActionListener(new ActionListener()按钮事件。 (5 )display 类的监听模块 在 display 中设置了三个监听器,都属于监听鼠标单击按钮事件,分别监听“退出” quit.addActionListener(new ActionListener()、 “返回” back.addActionListener(new ActionListener()、 “取款” qukuan.addActionListener(new java.awt.event.ActionListener()按钮事件。 (6 )Setpw 类的监听模块 在这个类中设置了两个监听器,它们是监听鼠标单击按钮事件,分别监听“确定” commit.addActionListener(new ActionListener()、 “退出” quit.addActionListener(new ActionListener()按钮事件。

三、系统调试分析

1.登陆界面
打开 MyEcplise,编译运行程序后,将会看到如图 3 所示的欢迎界面。点击确定之后, 会进入如图 4 所示的登陆界面。

图 3 欢迎登陆页面

图 4 登陆界面 进入到登陆界面后,需要输入账号和密码,当账号和密码正确时,才会进入到主界面。 账号和密码不符合时,会进入如图 4 所示的错误提示界面。初始账号和密码为“123456” 。

图 5 登陆出错提示界面

2.账号密码登陆
当输入的密码和卡号正确,单击确定后就会进入到主界面,选择服务,如图 6 所示, 点击相应的按钮就可以选择所需要的服务了,点击“退出”会回到登陆界面。

图 6 主界面

3.存款
点击存款,进入存款界面,如图 7 所示。

图 7 存款界面 当输入的钱数不是 100 的倍数时,就会弹出如图 7 所示的错误提示界面。输入正确时, 进入如图 9 所示的界面。选“是”的话,会进入查询余额界面,查看存款操作是否成功;选 “否”的话,会回到主界面。

图 8 存款出错提示界面

图 9 操作完成后的选择界面

4.取款
点击取款按钮,进入取款界面,如图 10 所示。当输入的钱数是负数,或者是 0,或者 不是 100 的倍数,又或者大于 5000 时,会弹出如图 11 所示的出错提示界面。当输入的钱数 符合要求时,会弹出如同存款操作一样的选择界面,如图 9 所示。

图 10 取款界面

图 11 取款错误提示界面

5.查询
点击主界面中的查询按钮, 或者是在存款和取款操作完成后的选择界面中选 “是” 的话, 就会进入到如图 12 所示的查询界面。 点击取款按钮, 会进入到取款界面。 初始金额为 50000, 图 12 中的余额是经过存款、取款操作以后的金额。

图 12 查询界面

6.修改密码
点击主界面中的修改密码按钮,进入到如图 13 所示的修改密码界面。新密码长度不小

于 6 位,不允许出现 6 位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入 相同的情况下才可以成功修改密码,弹出如图 14 所示的提示界面,点击确定后会回到主界 面。否则,密码修改不成功,点击确定按钮,界面没有反应。

图 13 修改密码界面

图 14 修改密码成功提示界面 经过上面的操作,既测试了程序的实现效果,又对系统的使用进行了详细的说明。从上 面的运行结果可以看出,程序基本上实现了所有的设计要求,而且运行正常。

四、总结
通过为时一周的课程设计,我受益匪浅,把平时所学的知识通通运用了进来,虽然平时 积淀的知识点比较少、比较单一,但是在这次实验中把零零碎碎的知识都连贯起来了,也达 到了课程设计的目的, 最主要的是通过一周的努力我终于用面向对象程序设计的知识做出了 这个“ATM 柜员机模拟系统” 。由于知识的积淀比较少,且有些知识掌握不太牢靠,记忆模 模糊糊的,最后决定恶补一下落下的知识点再进行程序的设计。第一天,去图书馆借了相关 图书,把知识点打牢,然后参考了相似的的几个实例,并进行了一些分析和总结。基础功课 做好以后第二天正式开工,选定好了题目,进行方法选择、框架设计、画出流程图、UML 图, 进行了初步的程序设计构想。第三天,编写程序代码,这个过程我觉得是最艰难的,因为代 码太多,还有 API 接口不是很熟悉,所以要经常翻阅手册,花费了很多时间。程序一不小心 就会出错不能运行,还需要认真检查,细心细心加细心才能做好。反复的进行分析调试,最 后一天把程序调试通过后,进行课程设计报告的撰写。虽然很幸苦但是,最终的成果还是令 人满意的,最后感谢指导老师对我们帮助和支持。 在这次的课程设计中,我主要运用了 Java 图形界面编程方面的知识,加深了对 Java 语言中各个基础知识点的了解和应用, 将自己所学的知识运用到实际操作当中, 而不再是纸 上谈兵。 通过这次设计, 我深刻感受到了面向对象语言中类库的强大功能, 掌握了运用 Java 中的类实现某些基本功能, 并学会了自己查询使用类的方法, 为以后的面向对象语言的自学 奠定了基础。 在这次课程设计中, 我查了很多资料, 很好的锻炼了自己的查阅资料的能力和快速吸收 新知识的能力。同时,也加深了与同学的交流,在设计过程中,我们互相帮助,共度难关, 培养了很好的默契。总之,在这次课程设计中,我学到了很多的知识,同时也感谢我的同学 的帮助和指导。在以后的学习当中,我会更加努力的学习好专业知识,并将所学的知识用于 实践当中去,以便牢固掌握知识。

五、参考文献
[1] 叶核亚. Java 程序设计实用教程(第 3 版.电子工业出版社,2010 [2] 耿祥义. JAVA 课程设计.清华大学出版,2009 [3] 王文涛,袁海燕 JAVA 实用程序设计 100 例[M]北京:人民邮电出版社,2005.5 [4] 雍俊海 JAVA 程序设计[M]北京:清华大学出版社,2006.8 [5] 刘宝林 JAVA 程序设计与案例[M]北京:高等教育出版社,2006.11

[6] 史斌星,史佳 .Java 基础及应用教程 [M].北京.清华大学出版社.2007.27.15.101. [7] Y.Daniel Liang.Java 语言程序设计[M].北京.机械工业出版社.2008.

六、附录 源代码
程序源代码:
/*********API接口************/ import javax.swing.*; import javax.swing.JOptionPane; import java.awt.event.*; import java.awt.*; public Account() { /***********主类*****************/ } public class ATMmodel { public void setpw(String Account myaccount=new Account();//账户实 例化 this.password=password; Load load=new Load(); } MainFrame Jmain=new MainFrame();//主框架 实例化 Take take=new Take(); count-=money;//取款后再原来基础上减所取 Input input=new Input(); Display dis=new Display(); Setpw setpw=new Setpw();//设置密码实例化 /************ 主方法******************/ public ATMmodel() { JOptionPane.showMessageDialog(null,"欢 迎使用ATM柜员模拟系统!");//进入主界面时用 JOptionPane.showMessageDialog() ;弹出系统提 示 return count;//获取余额 } } public static void main(String[] args) { public String getaccount(){ ATMmodel atm=new ATMmodel();//主函数 实例化 } /**************创建账户**********/ class Account { private int count=10000; //初 return account;//获取账号 } public String getpw(){ return password;//获取密码 } 部分 } public int get(){ 部分 } public void reccount(int money){ //reccount 存款 public void deccount(int money){ //deccount 取款 password){ //设置密码 //账户函数 始账户余额10000 private String account="123456"; 始账号 private String password="123456"; 始密码 //初 //初

count+=money;//存款后在原来基础上加所存

ActionListener() { } /*********************主界面 ************************/ class MainFrame extends JFrame { 方法由JFrame继承而来 public JButton checked; public JButton cunkuan; public JButton quit; public JButton qukuan; public JButton reset; //检测 //存款 //退出 //取款 //重设 }); //主框架 事件响应

//设置事件监听

public void actionPerformed(ActionEvent evt) { // 活动

cunkuanActionPerformed(evt); }

qukuan.setText("取款"); qukuan.addActionListener(new ActionListener() { public void

//框架按钮参数 public MainFrame() { //主框架函数

actionPerformed(ActionEvent evt) { qukuanActionPerformed(evt); } }); checked.setText("查询");

initComponents(); //添加组件 this.setLocationRelativeTo(null); // 设置窗口相对于指定组件的位置 this.setVisible(false); //隐藏其他窗口

checked.addActionListener(new } /* 控件初始化*/ private void initComponents() { 始化添加组件的和添加监听器 cunkuan = new JButton(); qukuan = new JButton(); checked = new JButton(); reset = new JButton(); quit = new JButton(); }); reset.setText("修改密码"); reset.addActionListener(new ActionListener() { setDefaultCloseOperation(WindowConstant s.EXIT_ON_CLOSE);//退出程序 setTitle("ATM柜员模拟程序"); setName("mianframe");//设置名称 setResizable(false); 大小不可改变 cunkuan.setText("存款"); “cunkuan”转换成“存款” cunkuan.addActionListener(new //将 //窗口 }); quit.setText("退出"); quit.addActionListener(new ActionListener() { } public void actionPerformed(ActionEvent evt) { resetActionPerformed(evt); checkedActionPerformed(evt); } //初 ActionListener() { public void actionPerformed(ActionEvent evt) {

public void actionPerformed(ActionEvent evt) { quitActionPerformed(evt); } ) });

.addPreferredGap(ja vax.swing.LayoutStyle.ComponentPlacement.RE LATED, 143, Short.MAX_VALUE) .addComponent(quit)

.addComponent(checked)) //程序界面划分,界面布局 // .addContainerGap()) GroupLayout layout = new GroupLayout(getContentPane()); //GroupLayout它将组件按层次分组,以决定它们 在 Container 中的位置 分 ); layout.setVerticalGroup( //垂直划

getContentPane().setLayout(layout);//内容面 板

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti

layout.setHorizontalGroup( 平划分

//水

alGroup() .addGap(46, 46, 46) .addGroup(layout.createPara

layout.createParallelGroup(GroupLayout.Alig nment.LEADING) .addGroup(layout.createSequenti alGroup()

llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(cunkuan) .addComponent(reset))

.addContainerGap() .addGap(51, 51, 51) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(layout.create SequentialGroup() .addComponent(cunku an) .addPreferredGap(ja vax.swing.LayoutStyle.ComponentPlacement.RE LATED, 105, Short.MAX_VALUE) ); .addComponent(reset )) .addGroup(javax.swing.G roupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(qukua n) } private void quitActionPerformed(ActionEvent evt) { 别是否退出 // 识 pack();//使此 JFrame 的子组件按其首 选大小进行布局 .addComponent(quit) .addComponent(qukuan)) .addGap(57, 57, 57) .addComponent(checked) .addGap(39, 39, 39)) .BASELINE) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment

load.setVisible(true); this.setVisible(false); } private void resetActionPerformed(ActionEvent evt) { 识别是否修改 setpw.setVisible(true); this.setVisible(false); } private void checkedActionPerformed(ActionEvent evt) { //识别是否查询 dis.setVisible(true); this.setVisible(false); } private void qukuanActionPerformed(ActionEvent evt) { 识别是否取款 take.setVisible(true); 置标题 this.setVisible(false); // // }

initComponents(); //初始化添加组件 的和添加监听器 this.setLocationRelativeTo(null);// 使窗口至于屏幕中央 this.setVisible(true);

private void initComponents() { jL1 = new JLabel(); jL2 = new JLabel(); accountnum = new JTextField();//允许 编辑单行文本 commit = new JButton(); Jpassword = new JPasswordField();// 单独提供它可以较方便地安全更改 JTextField 的 UI 而不影响密码输入 //对齐方法

setDefaultCloseOperation(WindowConstants.EX IT_ON_CLOSE); setTitle("ATM柜员模拟程序"); //设

setResizable(false);//窗口大小不可 } private void cunkuanActionPerformed(ActionEvent evt) { //识别是否存款 input.setVisible(true); this.setVisible(false); } } /********登录界面********/ class Load extends JFrame{ public JPasswordField Jpassword; public JTextField accountnum;// public JButton commit;//增删 private JLabel jL1;//设置对齐 private JLabel jL2; public Load() { }); /**********界面登陆设计**********/ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); } 事件监听 public void actionPerformed(java.awt.event.ActionEvent evt) { commitActionPerformed(evt); jL2.setText("密码:"); commit.setText("确定"); commit.addActionListener(new java.awt.event.ActionListener() { // 设置 改变 jL1.setText("账号:");

.addContainerGap(72, getContentPane().setLayout(layout);//获取组 件窗格 layout.setHorizontalGroup( Short.MAX_VALUE)) ); layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti alGroup() .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(layout.create SequentialGroup()

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti alGroup() .addGap(85, 85, 85) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(accountnu

.addContainerGap(50, Short.MAX_VALUE) .addGroup(layout.cr eateParallelGroup(javax.swing.GroupLayout.A lignment.TRAILING)

m, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jL1)) .addGap(41, 41, 41)

.addComponent(j L1)//添加组件jL1 .addComponent(j L2)) .addComponent(jL2) .addGap(31, 31, 31) .addComponent(Jpassword, .addGroup(layout.cr eateParallelGroup(javax.swing.GroupLayout.A lignment.LEADING, false) .addComponent(J password) .addComponent(a ccountnum, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))) .addGroup(layout.create SequentialGroup() .addGap(122, 122, 122) .addComponent(commi t))) } private void commitActionPerformed(ActionEvent evt) { ); pack(); .addGap(64, 64, 64)) javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swin g.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE) .addComponent(commit) .BASELINE) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment

if(accountnum.getText().equals(myaccoun t.getaccount()) && Jpassword.getText().equals(myaccount.getpw( )))//识别密码是否与初始密码一致 { Jmain.setVisible(true); this.setVisible(false); accountnum.setText("");

jL1 = new JLabel(); jT1 = new JTextField(); commit = new JButton(); back = new JButton(); quit = new JButton(); clear = new JButton();

setDefaultCloseOperation(WindowConstants.EX Jpassword.setText(""); } else{ IT_ON_CLOSE); jL1.setText("取款金额:"); commit.setText("确定"); commit.addActionListener(new JOptionPane.showMessageDialog(null,"密 码与账户不匹配,请重新输入","出错提示",1);// 密码不正确的提示 accountnum.setText(""); commitActionPerformed(evt); Jpassword.setText(""); } } }); } back.setText("返回"); } back.addActionListener(new /*******取款界面********/ class Take extends JFrame { public JButton back; public JButton clear; public JButton commit; private JLabel jL1; public JTextField jT1; public JButton quit; String str=""; public Take() { initComponents(); this.setLocationRelativeTo(null); this.setVisible(false); } private void initComponents() { }); clear.setText("清除"); } evt) { quitActionPerformed(evt); }); quit.setText("退出"); quit.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent } ActionListener() { public void actionPerformed(ActionEvent evt) { backActionPerformed(evt); public void actionPerformed(ActionEvent evt) { ActionListener() {

clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { clearActionPerformed(evt); } )) }); t)

.addComponent(commi

.addPreferredGap(ja vax.swing.LayoutStyle.ComponentPlacement.RE LATED, 147, Short.MAX_VALUE) .addComponent(back)

.addContainerGap(69, javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); ); getContentPane().setLayout(layout); layout.setVerticalGroup( layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.Grou layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti .addGroup(layout.createSequenti alGroup() .addGap(103, 103, 103) .addGap(41, 41, 41) .addGroup(layout.createPara .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addComponent(jL1) .addGroup(layout.create SequentialGroup() .addComponent(jL1) .addGap(33, 33, 33) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.create SequentialGroup() .addComponent(clear ) .addGap(29, 29, 29) .addPreferredGap(ja vax.swing.LayoutStyle.ComponentPlacement.RE LATED, 147, Short.MAX_VALUE) .addComponent(quit) ) .addGroup(layout.create SequentialGroup() .addComponent(clear) .addComponent(quit)) .addContainerGap(65, .BASELINE) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(61, 61, 61) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(commit) .addComponent(back)) llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) alGroup() pLayout.Alignment.LEADING) javax.swing.GroupLayout.PREFERRED_SIZE))

Short.MAX_VALUE)) ); pack(); } private void clearActionPerformed(ActionEvent evt) { str=""; jT1.setText(str); } private void quitActionPerformed(ActionEvent evt) { load.setVisible(true); this.setVisible(false); } private void backActionPerformed(ActionEvent evt) {

ON) {

dis.set(String.valueOf(myaccount.get())); str=""; jT1.setText(str); dis.setVisible(true); this.setVisible(false); } else { Jmain.setVisible(true); this.setVisible(false); } } else{ Jmain.setVisible(true); this.setVisible(false); JOptionPane.showMessageDialog(null," 取款金 额不能为负数"+"\n取款金额不能为0"+"\n取款金 额必须是100的倍数"+

}

private void commitActionPerformed(ActionEvent evt) {

"\n金额一次不能超过5000"+"\n 请重新输入你要取的金额数","出错提示",1);// 如果多次输错的提示 str="";

if(Integer.parseInt(jT1.getText())>0 && Integer.parseInt(jT1.getText())%100==0 && Integer.parseInt(jT1.getText())<=5000){ 取款数必须为100的整数且不可超过5000 } myaccount.deccount(Integer.parseInt(jT1.get Text())); int result=javax.swing.JOptionPane.showConfirmD ialog(null,"是否显示余额? ","",javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE); private JLabel jL1; private JTextField jT1; if(result==javax.swing.JOptionPane.YES_OPTI String str=""; /***********存款界面*********/ class Input extends JFrame { private JButton clear; private JButton commit; // } jT1.setText(str); }

public Input() { initComponents(); this.setLocationRelativeTo(null);

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti alGroup()

this.setResizable(false); .addGap(47, 47, 47) this.setVisible(false); .addGroup(layout.createPara } private void initComponents() { jL1 = new JLabel(); jT1 = new JTextField(); commit = new JButton(); clear = new JButton(); setDefaultCloseOperation(WindowConstants.EX IT_ON_CLOSE); jL1.setText("存款金额:"); commit.setText("确认"); )) commit.addActionListener(new ActionListener() { SequentialGroup() public void actionPerformed(ActionEvent evt) { commitActionPerformed(evt); } }); clear.setText("清除"); clear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { layout.createParallelGroup(javax.swing.Grou clearActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( alGroup() .addGap(88, 88, 88) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(jL1) pLayout.Alignment.LEADING) .addGroup(layout.createSequenti .addComponent(jL1) .addGap(27, 27, 27) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(50, Short.MAX_VALUE)) ); layout.setVerticalGroup( .addGroup(layout.create 111) .addComponent(clear t) .addGap(111, 111, SequentialGroup() .addGap(12, 12, 12) .addComponent(commi llelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(layout.create

.addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(87, 87, 87) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(clear) .addComponent(commit)) if(result==javax.swing.JOptionPane.YES_OPTI .addContainerGap(88, Short.MAX_VALUE)) { ); pack(); str=""; }// </editor-fold> jT1.setText(str); dis.setVisible(true); private void clearActionPerformed(ActionEvent evt) { str=""; jT1.setText(str); } else { Jmain.setVisible(true); private void commitActionPerformed(java.awt.event.Action Event evt) { } else if(Integer.parseInt(jT1.getText())%100= =0) { JOptionPane.showMessageDialog(null,"存 int a=Integer.parseInt(jT1.getText()); if(a<0) } JOptionPane.showMessageDialog(null,"存 款不能为负数","出错",1); else myaccount.reccount(a); } /**********显示余额界面**********/ } 款金额必须为100的整数倍!"+"\n请确认你的金额 ","出错提示",1); jT1.setText(""); { } this.setVisible(false); } this.setVisible(false); ON) ); int result=javax.swing.JOptionPane.showConfirmD ialog(null,"是否显示余额? ","",javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE); dis.set(String.valueOf(myaccount.get())

class Display extends JFrame { public JButton back; private JLabel jL1; public JTextField jT1; public JButton quit; public JButton qukuan; public Display() { initComponents(); evt) { });

}

back.setText("返回"); back.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent

backActionPerformed(evt); }

jT1.setText(String.valueOf(myaccount.get()) ); this.setLocationRelativeTo(null); this.setVisible(false); } public void public void set(String str){ jT1.setText(str); } private void initComponents() { jL1 = new JLabel(); jT1 = new JTextField(); quit = new JButton(); back = new JButton(); qukuan = new JButton(); }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( } actionPerformed(java.awt.event.ActionEvent evt) { qukuanActionPerformed(evt); }); qukuan.setText("取款"); qukuan.addActionListener(new java.awt.event.ActionListener() {

setDefaultCloseOperation(WindowConstants.EX IT_ON_CLOSE); jL1.setText("您的余额为:");

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti alGroup()

jT1.setEditable(false); .addGap(27, 27, 27) quit.setText("退出"); .addComponent(jL1) quit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jT1, quitActionPerformed(evt); javax.swing.GroupLayout.PREFERRED_SIZE, 143, .addPreferredGap(javax.swin g.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(36, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayo ut.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(215, Short.MAX_VALUE) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .TRAILING) .addComponent(back) .addComponent(qukuan) .addComponent(quit)) .addContainerGap()) ); layout.setVerticalGroup( ignment.LEADING) layout.cre ateParallelGroup(javax.swing.GroupLayout.Al } private void private void } ); pack();

.addContainerGap())

qukuanActionPerformed(ActionEvent evt) { take.setVisible(true); this.setVisible(false);

quitActionPerformed(ActionEvent evt) { load.setVisible(true); this.setVisible(false); } private void backActionPerformed(ActionEvent evt) { Jmain.setVisible(true); this.setVisible(false);

.addGroup(layout.createSequenti alGroup() .addGap(93, 93, 93) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(jL1) .addComponent(jT1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(54, 54, 54) .addComponent(qukuan) .addPreferredGap(javax.swin g.LayoutStyle.ComponentPlacement.RELATED) .addComponent(back) .addPreferredGap(javax.swin g.LayoutStyle.ComponentPlacement.RELATED) .addComponent(quit) } /*************修改密码 ********/ class Setpw extends JFrame { public JButton commit; public JLabel commitpw; public JPasswordField jPwcommit; public JPasswordField jPwnew; public JPasswordField jPwold; public JLabel newpw; public JLabel oldpw; public JButton quit; public Setpw() { initComponents(); this.setResizable(false); this.setLocationRelativeTo(null); }

//this.setVisible(false); } private void initComponents() { oldpw = new JLabel(); newpw = new JLabel(); commitpw = new JLabel();

javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) .addGroup(layout.createSequenti

jPwold = new JPasswordField(); jPwnew = new JPasswordField(); jPwcommit = new JPasswordField(); commit = new javax.swing.JButton(); quit = new javax.swing.JButton();

alGroup() .addGap(46, 46, 46) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addComponent(oldpw)

setDefaultCloseOperation(javax.swing.Window Constants.EXIT_ON_CLOSE); oldpw.setText("旧密码:"); newpw.setText("新密码:"); commitpw.setText("确认密码:"); commit.setText("确认"); commit.addActionListener(new java.awt.event.ActionListener() { SequentialGroup() public void actionPerformed(java.awt.event.ActionEvent evt) { commitActionPerformed(evt); } }); quit.setText("退出"); quit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { quitActionPerformed(evt); } }); javax.swing.GroupLayout layout = new )) ) t) )

.addComponent(newpw) .addComponent(commitpw)

.addGap(25, 25, 25) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .LEADING, false) .addGroup(layout.create

.addComponent(commi

.addPreferredGap(ja vax.swing.LayoutStyle.ComponentPlacement.RE LATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(quit)

.addComponent(jPwnew, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE) .addComponent(jPwold) .addComponent(jPwcommit

.addContainerGap(48, Short.MAX_VALUE))

); layout.setVerticalGroup(

.BASELINE) .addComponent(commit) .addComponent(quit))

layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING) pack(); .addGroup(layout.createSequenti alGroup() .addGap(53, 53, 53) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(oldpw) .addComponent(jPwold, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(36, 36, 36) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE) .addComponent(newpw) .addComponent(jPwnew, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) { } private void

.addGap(36, 36, 36)) );

commitActionPerformed(ActionEvent evt) { boolean flag=false;//标志密码不能出现全 部相同的数字 if(!jPwold.getText().equals(myaccount.g etpw()))

JOptionPane.showMessageDialog(null,"你 输入的密码与老密码不匹配!","错误提示 ",1);//1是符号 } else if(jPwnew.getText().length()<6) 二是标题

JOptionPane.showMessageDialog(null,"新 密码长度必须大于或等于6位","错误提示",1); else{ //用一个循环来查询密码是否全部一样 for(int

.addGap(40, 40, 40) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment .BASELINE)

i=0;i<jPwnew.getText().length();i++) {

if(jPwnew.getText().charAt(0)==jPwnew.g .addComponent(commitpw) .addComponent(jPwcommit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swin g.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE) .addGroup(layout.createPara llelGroup(javax.swing.GroupLayout.Alignment } } else{ flag=false; break; etText().charAt(i)) flag=true;

//密码全部一样则给出提示 if(flag) JOptionPane.showMessageDialog(null,"密 码不能全都相同","错误提示",1); //以上情况都没出现则修改成功 else if(jPwold.getText().equals(myaccount.getpw( )) && jPwnew.getText().equals(jPwcommit.getText() )) { myaccount.setpw(jPwnew.getText()); JOptionPane.showMessageDialog(null,"密 码修改成功,请记住你的新密码","",1); Jmain.setVisible(true); this.setVisible(false); } } } private void quitActionPerformed(java.awt.event.ActionEv ent evt) { load.setVisible(true); this.setVisible(false); } } }


 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评