大佬教程收集整理的这篇文章主要介绍了基于JavaSwing ATM取款机系统的设计和实现,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
前言:
本项目是使用Java swing开发c;可实现ATM系统/银行系统的基本登陆、转账、查询余额、存取款业务。界面设计比较简介、适合作为Java课设设计以及学习技术使用。
需求分析:
随着生活水平的提高c;消费量的增大c;开销也越来越大c;自然离不开的就是钱。人们有的要取钱c;有的要存钱c;可是只能去银行c;而银行的遍布并不是很广c;它可能在人流密集度比较大的地方会设立c;或者稍大范围内设立一个c;但是对于比较偏远地区的人们c;无疑造成了非常大的困难。那么c;如何来解决这个问题那?研发ATM柜员机即为广大用户提供了便捷c;改善了生活。您无需再到银行排队办理一些简单的业务c; ATM柜员机为您提供取款c;存款c;余额查询c;修改密码等功能操作。而且ATM的遍及范围远远大于银行c;主要是ATM的自身功能容易实现日容易布局c;不需要耗费大量的空间c;人力及物力c;可以在很多点来设立。也正是在这种情况下c; ATM柜员机得到了人们的喜爱并得到了大量的普及c;可以说对银行和人们都非常有益的。本系统通过设计与开发Windows系统c;主要完成了余额查询功能c;取款功能c;存款功能c;转账功能c;退出系统功能c;目的在于通过 ATM自动存取款 机实现一些简单的动能。
用户登录、注册、重置、存款、查询余额、取款、转账、更改密码、退卡等具体功能
功能截图:
运行程序启动mian方法进入登录页面
存入输入的金额点击确认完成存款、存款的时候输入的必须是整数
查询自己的余额以及操作记录信息
取款金额不能大于账户余额
转账的时候必须正确输入用户id信息、否则转款失败
输入原密码进行校验后、输入2次相同的新密码完成修改密码功能
这个ATM暂时没用数据库、是以文本txt的形式进行存储数据、更方便快捷简单话
部分关键代码:
public static void main(String[] args)throws Exception {
usersList = new ArrayList<Account>();
//System.out.println(usersList);
/**********************用户文本**********************/
File users = new File("users.txt");
if (!users.exists()) {
try {
users.createNewFile();
Writer fw = new FileWriter("users.txt");
fw.write("123456 123456 10000");
fw.flush();
fw.close();
} catch (Exception e1) {
JOptionPane.showmessageDialog(null, "@R_894_10589@文档失败");
}
}
usersFile = users;//创建用户文档c;存储用户账户c;密码c;余额信息;
usersListRead();
usersListupdate();
/*****************************Login****************************/
LoginGui loginGui = new LoginGui();
}
package atm;
//import com.sun.deploy.util.SyncFileAccess;
//import com.sun.org.apache.regexp.internal.RE;
import javax.swing.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class Account {
int money;
String id;//账号名
String password;
Date now=new Date();
Date currentTime;
SimpleDateFormat formatter;
Reader fr;
;
public Account(String id, String password, String money) {//构造方法
this.id = id;
this.password = password;
this.money=Integer.parseInt(money);
}
public void outMoney (int money)throws Exception {//抛出异常c;由相关的界面类弹窗处理异常,下面几个方法同理
//如在取钱界面取钱c;则会调用此函数c;进行try/catch处理c;获得这个函数的异常c;弹窗说明异常
if (money > this.money) {
throw new Exception("余额不足");
}
if(money<0)
{
throw new Exception("不能取出负数");
}
formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss");//时间格式
currentTime = new Date();//当前时间
String dateString = formatter.format(currentTimE);//处理当前时间格式
Writer fw = new FileWriter(Test.filE);
fw.write(Test.recordString.append(dateString + "t" + Test.currentAccount.id + "t取出" + money + "元rn").toString());//将这次的取钱行为添加到记录文件中
fw.flush();//写进文件
fw.close();
this.money -= money;
Test.usersListupdate();//更新用户文档(信息)
}
public void inMoney(int money)throws Exception
{
try {
Writer fw = new FileWriter(Test.filE);
// System.out.println(Test.filE);
formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
currentTime=new Date();
String dateString=formatter.format(currentTimE);
fw.write(Test.recordString.append(dateString+"t"+Test.currentAccount.id+"t存入" + money + "元rn").toString());
fw.flush();//写进文件
fw.close();
this.money+=money;
Test.usersListupdate();//更新当前用户信息
}
catch (Exception e1)
{
throw new Exception("写入记录失败");
}
}
public void transfer(int money,String id)throws Exception//转账
{
if(id.equals(Test.currentAccount.id))
{
throw new Exception("不能转给自己");
}
if(money>this.money)
{
throw new Exception("余额不足");
}
if(money<0) {
throw new Exception("不能转入负数");
}
for(int i=0;i<Test.usersList.size();i++)
{
if(Test.usersList.get(i).id.equals(id))//找到要转帐的用户
{
Test.usersList.get(i).money+=money;//转入
this.money-=money;//扣钱
FileWriter fw=new FileWriter(Test.filE);
formatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss");//声明时间格式
currentTime=new Date();//获取当前时间
String dateString=formatter.format(currentTimE);//转换时间格式
fw.write(Test.recordString.append(dateString+"t向"+id+"t转出"+money+"元rn").toString());//Test类中的静态字符串拼接上这个字符串覆盖写入当前用户文档
fw.close();
/********************向转入目标写入转账信息*************************/
try {
fr = new FileReader(id+".txt");//字符流
}
catch (Exception E)
{
System.out.println("字符流创建失败");
}
BufferedReader bfr = new BufferedReader(fr);
String temp="";
String temp1;
while ((temp1 = bfr.readLine()) != null)
{
temp+=temp1;
}
temp=temp.replace("元","元nr")+dateString+"t由"+Test.currentAccount.id+"t转进"+money+"元rn";
System.out.println(temp);
fw=new FileWriter(id+".txt");
fw.write(temp);
fw.close();
JOptionPane.showmessageDialog(null,"转账成功");
Test.usersListupdate();//更新用户文档
return;
}
}
throw new Exception("目标用户不存在");
}
public void Changepassword(String newpassword)throws Exception
{
if(newpassword.equals(this.password))
{
throw new Exception("原密码和新密码不能一样");
}
else
{
if(newpassword.equals(""))
{
throw new Exception("密码不能为空");
}
}
password=newpassword;
Test.usersListupdate();
}
}
package atm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Changepassword implements ActionListener{
public JpasswordField oldpassword,newpassword,checkpassword;
public JFrame iframe;
public JPanel ip0,ip1,ip2,ip3,ip4;
public JButton confirm,cancel,exit;
public Changepassword() {
iframe=new JFrame("更改密码");
iframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
ip2=new JPanel();
ip2.add(new JLabel("原密码:"));
oldpassword=new JpasswordField(20);
ip2.add(new JLabel("<html><br/><html>"));//换行
ip2.add(oldpassword);
ip0=new JPanel();
ip0.add(new JLabel("新密码:"));
newpassword=new JpasswordField(20);
ip0.add(new JLabel("<html><br/><html>"));//换行
ip0.add(newpassword);
ip4=new JPanel();
ip4.add(new JLabel("再次输入新密码:"));
checkpassword=new JpasswordField(20);
ip4.add(new JLabel("<html><br/><html>"));//换行
ip4.add(checkpassword);
ip3=new JPanel();
confirm=new JButton("确定");
ip3.add(confirm);
cancel=new JButton("返回");
ip3.add(cancel);
iframe.add(ip2);
iframe.add(ip0);
iframe.add(ip4);
iframe.add(ip3);
iframe.add(confirm);
iframe.add(cancel);
iframe.setLayout(new FlowLayout());
iframe.setVisible(true);
iframe.settitle("密码更改");//窗体标签
iframe.setSize(400, 200);//窗体大小
iframe.setLOCATIOnRelativeTo(null);//在屏幕中间显示(居中显示)
confirm.addActionListener(this);
cancel.addActionListener(this);
}
public void pw_clean() {
newpassword.setText("");
oldpassword.setText("");
checkpassword.setText("");
}
@Override
public void actionPerformed(ActionEvent E) {
if(e.getActionCommand().equals("确定")) {
if (Test.currentAccount.password.equals(oldpassword.getText())) {
try {
if(newpassword.getText().equals(checkpassword.getText())) {
if(newpassword.getText().length()>=6) {
Test.currentAccount.Changepassword(newpassword.getText());
JOptionPane.showmessageDialog(null, "更改密码成功");
iframe.setVisible(false);
Test.menu.mframe.setVisible(false);//关闭菜单界面
new LoginGui();
}else {
JOptionPane.showmessageDialog(null,"密码不能少于6位!n请重新输入","提示消息",JOptionPane.ERROR_messaGE);
pw_clean();
}
}
else
{
JOptionPane.showmessageDialog(null, "两次输入的密码不一致");
pw_clean();
}
}
catch (Exception e1) {//捕获账户类中更改密码函数的异常并弹窗显示
JOptionPane.showmessageDialog(null, e1.getmessage());
pw_clean();
}
} else {
JOptionPane.showmessageDialog(null, "原密码错误");
pw_clean();
}
}
else//如果点击cancel
{
iframe.setVisible(false);
}
}
}
文档结构图:
备注:项目来于网络、作者整理优化测试、若有侵权联系作者删除
总结:
在本次课程设计中我主要负责登陆界面部分和界面优化。通过这次课程设计。我学到了许多令我受益匪浅的知识。感觉java的界面设计和 mfc差不多。只是java没有可视化的界面做起来太累了。其他主要是类和对象的问题。实现起来还是挺简单的。
完整源码下载地址
JavaSwing系列项目推荐:
JavaSwing的经典坦克大战游戏设计实现
JavaSwing+Mysql的酒店管理系统设计实现
JavaSwing+mysql的图书管理系统设计实现
JavaSwing+mysql学生社团管理系统设计实现
打卡JavaSwing项目更新 1 / 100篇
大家可以点赞、收藏、关注、评论我啦
以上是大佬教程为你收集整理的基于JavaSwing ATM取款机系统的设计和实现全部内容,希望文章能够帮你解决基于JavaSwing ATM取款机系统的设计和实现所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。