这是在接受培训时,授课老师布置的项目。由于本人能力有限,还在学习,如有错误或不足之处,见谅。
里面的正则表达式部分都是我在网上找到的,这里已经忘了出处。。。
项目要求:
功能模块:
-
注册用户·
-
账号:不可选(从文件文本里获取最大ID+1)
-
用户名:用户可随便输
-
密码:需要验证密码的复杂性
-
确认密码:需要确认与密码是否相同
-
身份证号:需要确认,正则
-
电话:需要确认 正则
-
邮件:需要确认 正则
-
密码需要加密存储
-
-
用户登录·
-
输入正确的用户名密码后可实现登录,页面跳转,同时传值
-
输入错误的用户名密码不能登录 同时弹出错误对话框 同时需要验证错误次数
-
-
查询余额·
-
ID从FrameService传入(参考)
-
按ID查询余额,显示出来
-
-
取款·
-
按ID获取账户余额,如果输入值大于所取金额,提示用户
-
取款前需要再次确认
-
将记录存到磁盘
-
-
存款·
-
按ID获取账户余额
-
将记录存到磁盘
-
-
转账·
-
查询其它用户ID,如果没有,返回失败
-
转帐前需要再次确认
-
将记录存到磁盘
-
-
查询明细·
-
按ID列出最近记录
-
查询前需要再次确认
-
数据量大时需要分页显示
-
提供打印功能
-
-
贷款/还款·
-
修改密码·
-
需要验证老密码
-
-
锁定账户·
-
锁定后,不能使用,也不能被转入资金
-
-
关于本系统
-
显示本系统关于界面
-
代码:
结构:
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