银行ATM系统(IO存储、GUI界面)

这是在接受培训时,授课老师布置的项目。由于本人能力有限,还在学习,如有错误或不足之处,见谅。

里面的正则表达式部分都是我在网上找到的,这里已经忘了出处。。。

 

项目要求:

功能模块:

  1. 注册用户·

    1. 账号:不可选(从文件文本里获取最大ID+1)

    2. 用户名:用户可随便输

    3. 密码:需要验证密码的复杂性

    4. 确认密码:需要确认与密码是否相同

    5. 身份证号:需要确认,正则

    6. 电话:需要确认 正则

    7. 邮件:需要确认 正则

    8. 密码需要加密存储

  2. 用户登录·

    1. 输入正确的用户名密码后可实现登录,页面跳转,同时传值

    2. 输入错误的用户名密码不能登录 同时弹出错误对话框 同时需要验证错误次数

 

  1. 查询余额·

    1. ID从FrameService传入(参考)

    2. 按ID查询余额,显示出来

 

  1. 取款·

    1. 按ID获取账户余额,如果输入值大于所取金额,提示用户

    2. 取款前需要再次确认

    3. 将记录存到磁盘

  2. 存款·

    1. 按ID获取账户余额

    2. 将记录存到磁盘

  3. 转账·

    1. 查询其它用户ID,如果没有,返回失败

    2. 转帐前需要再次确认

    3. 将记录存到磁盘

  4. 查询明细·

    1. 按ID列出最近记录

    2. 查询前需要再次确认

    3. 数据量大时需要分页显示

    4. 提供打印功能

  5. 贷款/还款·

  6. 修改密码·

    1. 需要验证老密码

  7. 锁定账户·

    1. 锁定后,不能使用,也不能被转入资金

  8. 关于本系统

    1. 显示本系统关于界面

 

代码:

结构:

javaATM项目

 

windows部分:

ChangePwdFrame:

package window;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import action.ChangePwdAction;

/*
 * 修改密码
 */
public class ChangePwdFrame {
	
	int width = 300;
	int height = 250;

//	使用静态变量,便于后边调用
	public static JTextField password = new JTextField();
	public static JTextField newPassword = new JTextField();
	public static JTextField confirm = new JTextField();
	
	public void changePwd() {
		
		JFrame jf = new JFrame("Change password");
		
		jf.setLayout(null);
		
		JLabel passwordLab = new JLabel("password:");
		JLabel newPasswordLab = new JLabel("newPassword:");
		JLabel confirmLab = new JLabel("confirm:");
		JButton submit = new JButton("submit");
		
		passwordLab.setSize(100, 30);
		confirmLab.setSize(100, 30);
		newPasswordLab.setSize(100, 30);
		password.setSize(130, 30);
		confirm.setSize(130, 30);
		newPassword.setSize(130, 30);
		submit.setSize(80, 30);
		
		passwordLab.setLocation(30, 10);
		password.setLocation(120, 10);
		newPasswordLab.setLocation(30, 50);
		newPassword.setLocation(120, 50);
		confirmLab.setLocation(30, 90);
		confirm.setLocation(120, 90);
		submit.setLocation(110, 150);
		
		jf.add(passwordLab);
		jf.add(confirmLab);
		jf.add(password);
		jf.add(confirm);
		jf.add(newPasswordLab);
		jf.add(newPassword);
		jf.add(submit);
		
		submit.addActionListener(new ChangePwdAction()); // 调用监听器
		
		jf.setVisible(true); // 可见
		jf.setSize(width, height);
		jf.setLocation((1366-width)/2, (768-height)/2); // 居中
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 关闭方式
	}
	
	// main函数用来测试
	public static void main(String[] args) {
		ChangePwdFrame l = new ChangePwdFrame();
		l.changePwd();
	}
}

 

CheckBalanceFrame

package window;

import javax.swing.JFrame;
import javax.swing.JLabel;

/*
 * 查询余额
 */

public class CheckBalanceFrame {
	
	int width = 300;
	int height = 150;
	public static JLabel username = new JLabel("");
	public static JLabel balance = new JLabel("0");
	
	public void checkBalance() {
		
		JFrame jf = new JFrame("CheckBalance");
		
//		GridLayout gr = new GridLayout();
//		jf.setLayout(gr);
		jf.setLayout(null);
		
		JLabel usernameLab = new JLabel("username:");
		JLabel balanceLab = new JLabel("balance:");
		
		usernameLab.setSize(80, 30);
		balanceLab.setSize(80, 30);
		username.setSize(120, 30);
		balance.setSize(120, 30);
	
		
		usernameLab.setLocation(80, 10);
		username.setLocation(150, 10);
		balanceLab.setLocation(80, 50);
		balance.setLocation(150, 50);

		
		jf.add(usernameLab);
		jf.add(username);
		jf.add(balanceLab);
		jf.add(balance);
		
		jf.setVisible(true);
		jf.setSize(width, height);
		jf.setLocation((1366-width)/2, (768-height)/2);
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
	
	public static void main(String[] args) {
		CheckBalanceFrame l = new CheckBalanceFrame();
		l.checkBalance();
	}
}

DepositFrame,实际中存款和贷款有不同,但在这个ATM项目,考虑到贷款要设置信用,设置卡的类型等,我没有把他们区别开来。存款=贷款,取款=还贷。

package window;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import action.DepositAction;

/*
 * 存款
 */
public class DepositFrame {
	
	int width = 300;
	int height = 200;
	public static JLabel username = new JLabel("");
	public static JTextField depositMoney = new JTextField();
	
	public void depositMoney() {
		
		JFrame jf = new JFrame("Deposit");

		jf.setLayout(null);
		
		JLabel usernameLab = new JLabel("username:");
		JLabel depositMoneyLab = new JLabel("money:");
		JButton submit = new JButton("submit");
		
		usernameLab.setSize(80, 30);
		depositMoneyLab.setSize(80, 30);
		username.setSize(120, 30);
		depositMoney.setSize(120, 30);
		submit.setSize(80, 30);
		
		usernameLab.setLocation(40, 10);
		username.setLocation(120, 10);
		depositMoneyLab.setLocation(40, 50);
		depositMoney.setLocation(120, 50);
		submit.setLocation(110, 100);
		
		jf.add(usernameLab);
		jf.add(depositMoneyLab);
		jf.add(username);
		jf.add(depositMoney);
		jf.add(submit);
		
		submit.addActionListener(new DepositAction());
		
		jf.setVisible(true);
		jf.setSize(width, height);
		jf.setLocation((1366-width)/2, (768-height)/2);
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
	
	public static void main(String[] args) {
		DepositFrame l = new DepositFrame();
		l.depositMoney();
	}
}

DetailsFrame

package window;

import java.awt.TextArea;

import javax.swing.JButton;
import javax.swing.JFrame;

import action.DetailsAction;


/*
 * 查询账单
 */
public class DetailsFrame {

	int width = 500;
	int height = 300;

	public static TextArea details = new TextArea(); //TextArea可以使用滚动条

	public void showDetails() {

		JFrame jf = new JFrame("Details");

		jf.setLayout(null);

		JButton printDetailsBtn = new JButton("Print");

		details.setSize(450, 200);
		details.setLocation(20, 10);
		printDetailsBtn.setSize(80, 30);
		printDetailsBtn.setLocation(200, 220);

		jf.add(printDetailsBtn);
		jf.add(details);
		printDetailsBtn.addActionListener(new DetailsAction());

		jf.setVisible(true);
		jf.setSize(width, height);
		jf.setLocation((1366 - width) / 2, (768 - height) / 2);
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	public static void main(String[] args) {
		DetailsFrame l = new DetailsFrame();
		l.showDetails();
	}
}

LoansFrame

package window;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import action.LoansAction;

/*
 * 贷款
 */
public class LoansFrame {
	
	int width = 300;
	int height = 200;
	public static JLabel username = new JLabel("");
	public static JTextField LoansMoney = new JTextField();
	
	public void LoansMoney() {
		
		JFrame jf = new JFrame("LoansMoney");
		
//		GridLayout gr = new GridLayout();
//		jf.setLayout(gr);
		jf.setLayout(null);
		
		JLabel usernameLab = new JLabel("username:");
		JLabel LoansMoneyLab = new JLabel("loans amount:");
		JButton submit = new JButton("submit");
		
		usernameLab.setSize(100, 30);
		LoansMoneyLab.setSize(100, 30);
		username.setSize(120, 30);
		LoansMoney.setSize(120, 30);
		submit.setSize(80, 30);
		
		usernameLab.setLocation(30, 10);
		username.setLocation(140, 10);
		LoansMoneyLab.setLocation(30, 50);
		LoansMoney.setLocation(140, 50);
		submit.setLocation(110, 100);
		
		jf.add(usernameLab);
		jf.add(LoansMoneyLab);
		jf.add(username);
		jf.add(LoansMoney);
		jf.add(submit);
		
		submit.addActionListener(new LoansAction());
		
		jf.setVisible(true);
		jf.setSize(width, height);
		jf.setLocation((1366-width)/2, (768-height)/2);
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
	
	public static void main(String[] args) {
		LoansFrame l = new LoansFrame();
		l.LoansMoney();
	}
}

LockAccountFrame

package window;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import action.LockAccountAction;
import action.UnLockAccountAction;

/*
 * 锁定账户
 */

public class LockAccountFrame {

	int width = 300;
	int height = 150;
	public static JLabel username = new JLabel("");

	public void lockAccount() {

		JFrame jf = new JFrame("lockAccount");

		// GridLayout gr = new GridLayout();
		// jf.setLayout(gr);
		jf.setLayout(null);

		JLabel usernameLab = new JLabel("username:");
		JButton lockBtn = new JButton("lock");
		JButton unlockBtn = new JButton("unlock");

		usernameLab.setSize(80, 30);
		username.setSize(120, 30);
		lockBtn.setSize(80, 30);
		unlockBtn.setSize(80, 30);

		usernameLab.setLocation(80, 10);
		username.setLocation(150, 10);
		lockBtn.setLocation(40, 50);
		unlockBtn.setLocation(160, 50);

		jf.add(usernameLab);
		jf.add(username);
		jf.add(lockBtn);
		jf.add(unlockBtn);
		lockBtn.addActionListener(new LockAccountAction());
		unlockBtn.addActionListener(new UnLockAccountAction());

		jf.setVisible(true);
		jf.setSize(width, height);
		jf.setLocation((1366 - width) / 2, (768 - height) / 2);
		// jf.pack();
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	public static void main(String[] args) {
		LockAccountFrame l = new LockAccountFrame();
		l.lockAccount();
	}
}

LoginFrame

package window;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import action.LoginAction;
import service.FileService;

/*
 * 登录
 */
public class LoginFrame {

	int width = 300;
	int height = 200;
	public static JTextField usernameField = new JTextField();
	public static JPasswordField passwordField = new JPasswordField();
	static JFrame jf = new JFrame("log in");

	public void showLogin() {


		// GridLayout gr = new GridLayout();
		// jf
  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值