这个项目是本人的期末Java答辩作业
开发所用到的工具及环境
开发工具 IntelliJ IDEA 2023.1
jdk版本 jdk1.8 (传说中的Java8)
系统 Windows 11 23H2 x64 专业版
数据库采用 MySQL8.0.11 版本
选题为 ATM模拟程序
题目要求:
输入给定的卡号和密码(初始卡号为62250028和密码为123456)时,系统能登录ATM柜员机系统,用户可以按照以下规则进行操作:
1. 查询余额:初始余额为10000元
2. ATM取款:每次取款金额为100的倍数,总额不超过5000元,支取金额不允许透支
3. ATM存款:不能出现负存款
4. 修改密码:新密码长度不小于6位,不允许出现6位完全相同的情况,只有旧密码正确,新密码符合要求,且两次输入相同的情况下才可以成功修改密码
5. 要求数据采用文件存储,如果采用数据库存储数据,且界面实现采用了GUI,则酌情提档给分
在此基础之上,我还添加一些其他的功能,可以在我的Gitee仓库查看,传送门在文章结尾
在这里先附上一部分代码,仅供参考:
在本地使用项目,一定记得先修改sql包里的两个数据库配置修改为自己的数据库信息
然后创建数据表和插入测试数据
private static final String URL = "jdbc:mysql://localhost:3306/Gamedb_2";
private static final String USERNAME = "java_user";
private static final String PASSWORD = "1111";
首先是数据库的表
create table user_atm(
id_atm bigint not null primary key auto_increment,
name_atm varchar(30) not null,
password int not null,
balance bigint default 0
)auto_increment=62250030;
create table superUser_atm(
id_super varchar(10) not null primary key,
name_super varchar(30) not null,
password bigint not null
);
create table log_atm(
id_log bigint not null primary key auto_increment,
id_atm bigint not null,
time_atm datetime default current_timestamp
)auto_increment=1;
create table log_atm_super(
id_log bigint not null primary key auto_increment,
id_super varchar(255) not null,
time_atm datetime default current_timestamp
)auto_increment=1;
表有了,测试数据也得有吧
insert into superUser_atm values
('su1001','admin',1111);
insert into user_atm values
(62250028,'蔡永斌',123456,10000),
(62250029,'阮豪豪',147258,10000);
然后是项目的tree图
├─lib
└─src
└─com
└─paolu
├─jFrame
│ ├─superjFrame
│ │ └─secondaryJFrame
│ └─userjFrame
│ └─secondaryJFrame
├─sql
└─utils
这里解释一下
1. lib 数据库JDBC驱动
2. src 项目源代码
3. jFrame GUI界面
4. sql 数据库操作实现语句
5. utils 工具类及实体类
登录的首页,功能是选择身份 管理员或是普通用户
贴一下代码
package com.paolu.jFrame;
import com.paolu.jFrame.superjFrame.SuperLoginJFrame;
import com.paolu.jFrame.userjFrame.LoginJFrame;
import javax.swing.*;
import java.awt.*;
public class Login extends JFrame {
public Login() {
initLoginJFrame();
}
private void initLoginJFrame() {
initButton();
this.setTitle("ATM-Login");
this.setResizable(false);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int windowWidth = 800;
int windowHeight = 800;
this.setSize(windowWidth, windowHeight);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
int x = (screenWidth - windowWidth) / 2;
int y = (screenHeight - windowHeight) / 2;
this.setLocation(x, y);
this.setVisible(true);
}
private void initButton(){
int buttonWidth = 300;
int buttonHeight = 60;
int fontSize =50;
JButton userButton = new JButton("普通登录");
JButton superButton = new JButton("管理员登录");
userButton.setBounds(50, 520, buttonWidth, buttonHeight);
superButton.setBounds(450, 520, buttonWidth, buttonHeight);
userButton.setFont(new Font(userButton.getFont().getName(), Font.PLAIN, fontSize));
superButton.setFont(new Font(superButton.getFont().getName(), Font.PLAIN, fontSize));
userButton.addActionListener(e -> {
new LoginJFrame();
this.setVisible(false);
});
superButton.addActionListener(e -> {
new SuperLoginJFrame();
this.setVisible(false);
});
this.add(userButton);
this.add(superButton);
}
}
选择好后会分别跳转到不同的登录功能页面
在代码里设置了默认的用户和管理员
管理员的MainJFrame,默认显示这些信息和四个功能模块
用户的也差不多
就简单展示一点,余下的的在Gitee仓库里,有兴趣的朋友可以去看看