
前言:
本專案是使用Java swing開發,可實作ATM系統/銀行系統的基本登陸、轉賬、查詢余額、存取款業務,界面設計比較簡介、適合作為Java課設設計以及學習技術使用,
需求分析:
隨著生活水平的提高,消費量的增大,開銷也越來越大,自然離不開的就是錢,人們有的要取錢,有的要存錢,可是只能去銀行,而銀行的遍布并不是很廣,它可能在人流密集度比較大的地方會設立,或者稍大范圍內設立一個,但是對于比較偏遠地區的人們,無疑造成了非常大的困難,那么,如何來解決這個問題那?研發ATM柜員機即為廣大用戶提供了便捷,改善了生活,您無需再到銀行排隊辦理一些簡單的業務, ATM柜員機為您提供取款,存款,余額查詢,修改密碼等功能操作,而且ATM的遍及范圍遠遠大于銀行,主要是ATM的自身功能容易實作日容易布局,不需要耗費大量的空間,人力及物力,可以在很多點來設立,也正是在這種情況下, ATM柜員機得到了人們的喜愛并得到了大量的普及,可以說對銀行和人們都非常有益的,本系統通過設計與開發Windows系統,主要完成了余額查詢功能,取款功能,存款功能,轉賬功能,退出系統功能,目的在于通過 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, "創建用戶檔案失敗");
}
}
usersFile = users;//創建用戶檔案,存盤用戶賬戶,密碼,余額資訊;
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 {//拋出例外,由相關的界面類彈窗處理例外,下面幾個方法同理
//如在取錢界面取錢,則會呼叫此函式,進行try/catch處理,獲得這個函式的例外,彈窗說明例外
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 + "元\r\n").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 + "元\r\n").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+"元\r\n").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("元","元\n\r")+dateString+"\t由"+Test.currentAccount.id+"\t轉進"+money+"元\r\n";
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篇
大家可以點贊、收藏、關注、評論我啦
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/294197.html
標籤:java
