Java 银行管理系统源代码

合集下载

银行管理系统登陆界面java代码

银行管理系统登陆界面java代码
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label1 = new JLabel("账号");
label1.setBounds(85,110, 100, 40);
this.add(label1);
JLabel label2 = new JLabel("密码");
try {
rset=stmt.executeQuery(sql1);
if(rset.next()==false){JOptionPane.showMessageDialog(null, "输入账号错误", "提示",
JOptionPane.ERROR_MESSAGE); }
else
{
String sql2="select密码from账户where密码="+text2.getText();
label2.setBounds(85, 150, 100, 40);
this.add(label2);
text1 = new JTextField();
text1.setBounds(140, 115, 140, 25);
this.add(text1);
text2 = new JPasswordField();
stmt = con.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
if(ev.getSource()==button)
{ResultSet rset=null;

小型银行管理系统的部分代码介绍

小型银行管理系统的部分代码介绍

小型银行管理系统的部分代码介绍1.主要数据结构和类定义:a. Customer类:表示银行的客户,包含以下属性:- id: 客户唯一标识符- name: 客户姓名- address: 客户地址- accounts: 客户账户列表b. Account类:表示客户的账户,包含以下属性:- id:账户唯一标识符- type:账户类型(储蓄账户、支票账户等)- balance:账户余额c. Bank类:表示银行,包含以下属性:- name:银行名称- customers:银行客户列表2.添加客户功能:```javapublic void addCustomer(String name, String address, String phone)Customer customer = new Customer(name, address, phone);customers.add(customer);```3.添加账户功能:```javapublic void addAccount(String customerId, String accountType) Customer customer = getCustomerById(customerId);if (customer != null)Account account = new Account(accountType);customer.addAccount(account);}```4.存款功能:```javapublic void deposit(String customerId, String accountId, double amount)Customer customer = getCustomerById(customerId);if (customer != null)Account account = customer.getAccountById(accountId);if (account != null)account.deposit(amount);}}```5.取款功能:```javapublic void withdraw(String customerId, String accountId, double amount)Customer customer = getCustomerById(customerId);if (customer != null)Account account = customer.getAccountById(accountId);if (account != null)account.withdraw(amount);}}```6.转账功能:```javapublic void transfer(String customerId, String fromAccountId, String toAccountId, double amount)Customer customer = getCustomerById(customerId);if (customer != null)Account fromAccount = customer.getAccountById(fromAccountId);Account toAccount = customer.getAccountById(toAccountId);if (fromAccount != null && toAccount != null)fromAccount.withdraw(amount);toAccount.deposit(amount);}}```7.查找客户功能:```javapublic Customer getCustomerById(String customerId)for (Customer customer : customers)if (customer.getId(.equals(customerId))return customer;}}return null;```这些代码展示了小型银行管理系统的基本功能,包括添加客户、添加账户、存款、取款和转账等操作。

java银行管理系统代码

java银行管理系统代码

Java银行管理系统代码1. 简介银行管理系统是一个重要的金融应用程序,用于管理银行内部的各种业务和操作。

通过使用Java编程语言,我们可以实现一个功能完善的银行管理系统,用于处理各种银行相关的业务。

2. 功能我们的Java银行管理系统将具有以下主要功能:2.1 用户管理该系统将允许银行管理员创建、编辑和删除用户账户。

每个用户账户将包含基本信息,如姓名、地址、电话号码等。

管理员还可以为每个用户设定特定的访问权限。

2.2 账户管理该系统将允许用户创建和管理他们的银行账户。

用户可以查看其余额、存款、取款以及转账等操作。

用户可以选择将资金存入不同类型的账户,如储蓄账户、支票账户等。

用户还可以查看最近的交易记录。

2.3 贷款管理用户可以通过该系统申请贷款。

用户可以输入贷款金额、贷款年限等信息,并提交申请。

银行管理员将审核贷款申请,并根据用户的信用评级和其他条件决定是否批准贷款。

2.4 利率计算该系统将提供利率计算功能,用于计算存款的利息和贷款的利率。

用户可以输入存款金额、存款期限等信息,系统将根据银行设定的利率计算并显示利息。

同样,用户也可以输入贷款金额、贷款期限等信息,系统将计算并显示贷款的利率。

3. 实现3.1 数据模型我们将使用Java编程语言创建一系列类来表示银行管理系统的各种对象,如用户、账户、交易等。

我们将使用面向对象编程的原则来设计这些类,并使用适当的数据结构来存储和管理数据。

3.2 用户界面我们将使用Java Swing库创建一个用户界面,用于与用户进行交互。

用户界面将包含各种表单和按钮,用于输入和显示数据。

用户可以使用鼠标和键盘与系统进行交互。

3.3 业务逻辑我们将使用Java编程语言编写业务逻辑代码来处理各种银行相关的操作。

这些代码将实现用户管理、账户管理、贷款管理和利率计算等功能。

我们将使用适当的算法和数据结构来实现这些功能,并确保它们的正确性和安全性。

4. 使用4.1 安装和配置要使用Java银行管理系统,您需要在计算机上安装Java Development Kit (JDK)和Java Runtime Environment(JRE)。

java银行账户管理系统代码

java银行账户管理系统代码

Java银行账户管理系统代码简介银行账户管理系统是一个用于管理银行客户账户的软件系统。

该系统可以实现客户开户、存款、取款、转账等基本功能,同时提供了查询账户余额、查询交易记录等附加功能,便于客户管理自己的资金。

功能模块客户管理模块这个模块包括客户信息的增删改查功能。

系统可以记录客户的姓名、身份证号、手机号等基本信息。

账户管理模块这个模块包括账户的开户、销户、存款、取款、转账等功能。

代码实现客户类public class Customer {private String name;private String idCard;private String phoneNumber;// 构造方法public Customer(String name, String idCard, String phoneNumber) { = name;this.idCard = idCard;this.phoneNumber = phoneNumber;}// getter和setter方法public String getName() {return name;}public void setName(String name) { = name;}public String getIdCard() {return idCard;}public void setIdCard(String idCard) {this.idCard = idCard;}public String getPhoneNumber() {return phoneNumber;}public void setPhoneNumber(String phoneNumber) {this.phoneNumber = phoneNumber;}}账户类```java public class Account { private String accountNumber; private double balance; private Customer customer;// 构造方法public Account(String accountNumber, Customer customer) {this.accountNumber = accountNumber;this.customer = customer;}// 存款public void deposit(double amount) {balance += amount;}// 取款public void withdraw(double amount) {if (balance >= amount) {balance -= amount;} else {System.out.println(\。

java代码实现银行管理系统

java代码实现银行管理系统

java代码实现银⾏管理系统本⽂实例为⼤家分享了java银⾏管理系统的具体代码,供⼤家参考,具体内容如下银⾏业务调度⼀、系统要求1、银⾏内有6个业务窗⼝,1 - 4号窗⼝为普通窗⼝,5号窗⼝为快速窗⼝,6号窗⼝为VIP窗⼝。

2、有三种对应类型的客户:VIP客户,普通客户,快速客户(办理如交⽔电费、电话费之类业务的客户)。

3、异步随机⽣成各种类型的客户,⽣成各类型⽤户的概率⽐例为:VIP客户:普通客户:快速客户 = 1 :6 :3。

4、客户办理业务所需时间有最⼤值和最⼩值,在该范围内随机设定每个VIP客户以及普通客户办理业务所需的时间,快速客户办理业务所需时间为最⼩值(提⽰:办理业务的过程可通过线程Sleep的⽅式模拟)。

5、各类型客户在其对应窗⼝按顺序依次办理业务。

6、当VIP(6号)窗⼝和快速业务(5号)窗⼝没有客户等待办理业务的时候,这两个窗⼝可以处理普通客户的业务,⽽⼀旦有对应的客户等待办理业务的时候,则优先处理对应客户的业务。

7、随机⽣成客户时间间隔以及业务办理时间最⼤值和最⼩值⾃定,可以设置。

8、不要求实现GUI,只考虑系统逻辑实现,可通过Log⽅式展现程序运⾏结果。

⼆、系统简析1、有三种对应类型的客户:VIP客户,普通客户,快速客户,异步随机⽣成各种类型的客户,各类型客户在其对应窗⼝按顺序依次办理业务。

(1)、⾃⼰知道每个客户其实就是由银⾏的⼀个取号机器产⽣号码的⽅式来通知⽤户办理相关业务的。

所以,定义⼀个号码管理器对象,让这个对象不断地产⽣号码,就等于随机⽣成了客户。

(2)、因为有三类客户,每类客户的号码编排都是完全独⽴的,所以,我想到本系统⼀共要产⽣三个号码管理器对象,各⾃管理⼀类⽤户的排队号码。

这三个号码管理器对象统⼀由⼀个号码机器进⾏管理,这个号码机器在整个系统中始终只能有⼀个,所以,它要被设计成单例。

2、各类型客户在对应窗⼝按顺序依次办理业务,也可以说是各个窗⼝依次叫号。

(1)、各个窗⼝怎么知道该叫哪⼀个号了呢?它⼀定是问的相应的号码管理器,即服务窗⼝每次找号码管理器获取当前要被服务的号码。

面向对象银行管理系统JAVA代码

面向对象银行管理系统JAVA代码

面向对象银行管理系统JAVA代码面向对象模拟银行管理系统(java):一般银行账户分为:借记卡账户和信用卡账户借记卡账户DebitAccount :是指先存款后消费(或取现),没有透支功能的银行卡。

即存储卡账户,余额必须大于0。

信用卡账户CreditAccount :信用卡是一种非现金交易付款的方式,是简单的信贷服务。

在借记卡功能的基础上可以透支,但是有透支额度,即透支只能在一定的金额范围内透支。

信用额度是指银行在批准你的信用卡的时候给于你信用卡的一个最高透支的限额,你只能在这个额度内刷卡消费,超过了这个额度就无法正常刷卡消费本程序有五个类,一个账户父类,两个子类账户(借记,信用),一个Bank类,还有一个类包含主方法详细程序代码及注释如下:package src.day01;public class ACC {//父类,以下是共有属性和方法//卡号protected static long id;// 名字protected static String name;// 身份证protected static String personId;//电子邮件protected static String email;// 密码protected static long password;//余额protected static double balance;public ACC(){}public ACC(long id,String name,String personId,String email,long password,double balance ){ this.id = id;= name;this.personId = personId;this.email = email;this.password = password;this.balance = balance;}// 存款方法public static void deposit(double money){balance += money;System.out.println(“存款成功,你存入的金额为:" + money); }public long getId() {return id;}public void setId(long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {= name;}public String getPersonId() {return personId;}public void setPersonId(String personId) {this.personId = personId;}public String getEmail() {return email;}public void setEmail(String email) { this.email = email;}public long getPassword() {return password;}public void setPassword(long password) { this.password = password;}public double getBalance() {return balance;}public void setBalance(double balance) { this.balance = balance;}}package src.day01;import java.util.*;public class Bank {//先定义两个动态数组,其中ban用来存储借记卡数据,ba用来存储信用卡数据static Vector ban = new Vector();static Vector ba = new Vector();//i指借记卡卡号,每增加一个用户,i自增1//j指借记卡卡号,每增加一个用户,j自增1private static long i = __-__0;private static long j = __-__0;public Bank(){}//判断用户办理借记卡还是信用卡的相关业务public static void justy(int ch){boolean k = true ;while(k){if(ch ==1){System.out.println("你将要办理借记卡业务:");break;}else if(ch ==2){System.out.println("你将要办理信用卡业务:");break;System.out.println("输入指令错误,请重新输入:"); k=false;}}}//开户方法public static void register(int ch){justy(ch);Scanner re = new Scanner(System.in);System.out.println("请输入开户的用户名:"); String na =re.next();long key;//两次密码不同的话循环进行p: while (true){System.out.println("请输入密码:");long pa = re.nextLong();System.out.println("请再次输入密码:");long pa1 = re.nextLong();if(pa==pa1 ){key = pa1;}else{System.out.println("两次不相同,请重新输入");continue p;}}System.out.println("请输入身份证号:");String perId = re.next();System.out.println("请输入email地址:");String em = re.next();System.out.println("请输入开户金额:");double bal = re.nextDouble();//存储和输出过程,将以上输入的正确数据存储到相应的数组中if(ch==1){ DebitAcc De = new DebitAcc(i,na,perId,em,key,bal);ban.add(De);System.out.println("恭喜你开户成功:你的卡号为" + i);i++;}else if(ch==2){CreditAcc Cr = new CreditAcc(j,na,perId,em,key,bal);ba.add(Cr);System.out.println("恭喜你开户成功:你的卡号为" + j); j++;}System.out.println( "用户名:" + na );System.out.println("身份证:"+ perId );System.out.println("email:" +em );System.out.println("开户金额:" + bal );}//用户子菜单public static void MenuCu(){Scanner sc = new Scanner(System.in);while(true){System.out.println("欢迎使用银行系统");System.out.println("请输入指令:1、开户2 、登陆3、退出到上级"); int choice = sc.nextInt();switch(choice){case 1:openAccount();break;case 2:logIn();break;case 3:return;default :System .out .println("输入指令错误,请重新输入");break;}}}//开户方法总方法private static void openAccount(){System.out.println("你将要办理开户业务:");System.out.println("请输入你要选择的银行卡类型:1、借记卡2、信用卡");Scanner op = new Scanner(System.in);int ch = op.nextInt();register(ch);}//用户登陆总方法public static void logIn( ){System.out.println("欢迎进入用户登陆界面,请选择你要登陆的卡号类型:1、借记卡2、信用卡" );boolean o = true;boolean p =false;Scanner lo = new Scanner(System.in);int ch = lo.nextInt();justy(ch);l: while(o) {System.out.println("请输入你的卡号:");long user = lo. nextLong();if(ch==1){//调用对应数组的卡号群与输入卡号匹配,以下同理for(int i = 0;iBank.ban.size();i++){DebitAcc d = (DebitAcc)Bank.ban.get(i);if(user == d.id){System.out.println("请输入密码:");long password = lo.nextLong();//对密码进行正误判断,正则p为true,可向下进行,false 则直接返回输入卡号命令,即只有输密码一次机会p = pass(password) ;while(p){d.menu1();break;}}else{//卡号不存在进行的操作System.out.println("该卡号不存在,是否重新输入:1、继续2、返回上一级");int c =lo.nextInt();if(c==1){continue l;}else{return;}}}}else {for(int j =0;jBank.ba.size();j++){CreditAcc c = (CreditAcc)Bank.ba.get(j);if(user==c.id){System.out.println("请输入密码:");long password = lo.nextLong();p = pass(password) ;while(p){c.menu1();break;}}else{System.out.println("该卡号不存在,请重新输入:"); continue l;}}}}}//密码正误判断方法public static boolean pass( long password){if(password !=DebitAcc.password){System.out.println("密码错误!重新输入:"); return false;}else{return true;}}//管理员操作菜单public static void menuAd(){Scanner mc = new Scanner(System.in);while(true){System.out.println("欢迎使用银行系统");System.out.println("请输入指令:1、查看所有用户余额2 、查看信用卡用户总信用额度3、退出到上级");int m =mc.nextInt();case 1:checkBalance();break;case 2:checkCeiling();break;case 3:return;default:System.out.println("输入错误,请重试:");break;}}//营业员查询总余额public static void checkBalance(){double k =0.0;for(int i = 0;iBank.ban.size();i++){DebitAcc d = (DebitAcc)Bank.ban.get(i);k += d.balance;}for(int j=0;jBank.ba.size();j++){CreditAcc c = (CreditAcc)Bank.ba.get(j);k+=c.balance;}System.out.println("本银行账户的总余额为:" + k);}public static void checkCeiling(){double k =0.0;for(int j=0;jBank.ba.size();j++){CreditAcc c = (CreditAcc)Bank.ba.get(j);k+=c.ceiling;}System.out.println("本银行信用卡账户的总信用度为:" + k);//银行系统总菜单public static void menuWel(){Scanner b = new Scanner(System.in);while(true){System.out.println("欢迎使用银行系统");System.out.println("请输入指令:1、营业管理员2、普通用户int ba =b.nextInt(); 3、退出");case 1:menuAd();break;case 2:MenuCu();break;case 3:System .out .println("感谢你的使用,欢迎下次光临");System.exit(0);}}}package src.day01;import java.util.*;public class CreditAcc extends ACC {//信用卡子类先定义信用额度为一常量public double ceiling = 500.0;CreditAcc(){super();}CreditAcc(long id,String name,String personId,String email,long password,double balance){ super(id,name,personId,email,password,balance);}//取款方法public void withdraw(double money){if(moneybalance){System.out.println("你的余额已不足,是否透支?1.透支2.不透支"); Scanner cr = new Scanner (System.in);int c = cr.nextInt();switch(c){case 1:if(ceiling + balancemoney){System.out.println("信用度不足,无法透支,请重新输入"); }else{ceiling = (ceiling +balance)-money;balance = 0;}break;case 2:break;default:System.out.println("操作错误,请重新输入");break;}}}//查询方法public void show(){System.out.println("姓名:" +name +" 卡号:" + id);if(balance==0){System.out.println("你的余额为0,信用度为:" + ceiling); }else{System.out.println("你的余额为:" + balance);}}// 信用卡子菜单public static void menu1(){boolean b=true;while(b){System .out.println("请输入指令:1、取款2、存款3、查询4、退出到上级"); Scanner men = new Scanner(System.in);int m =men.nextInt();switch(m){case 1:System.out.println("请输入取款金额:");double money = men.nextDouble();DebitAcc.withdraw(money);break;case 2:System.out.println("请输入存款金额:");double money1 = men.nextDouble();DebitAcc.deposit(money1);break;case 3:DebitAcc.show();case 4:return;}}}}package src.day01;import java.util.Scanner;public class DebitAcc extends ACC {//借记卡子类DebitAcc(){super();}DebitAcc(long id,String name,String personId,String email,long password,double ancbalancee){super (id,name,personId,email,password,ancbalancee) ;}//借记卡子菜单public static void menu1(){boolean b=true;while(b){System .out.println("请输入指令:1、取款2、存款3、查询4、退出到上级"); Scanner men = new Scanner(System.in);int m =men.nextInt();switch(m){case 1:System.out.println("请输入取款金额:");double money = men.nextDouble();DebitAcc.withdraw(money);case 2:System.out.println("请输入存款金额:");double money1 = men.nextDouble();DebitAcc.deposit(money1);break;case 3:DebitAcc.show();break;case 4:return;}}}//取款方法,不可透支public static void withdraw(double money){if(money balance){System.out.println("你的余额已不足,无法透支,请你重新输入:"); return;}balance-=money;}//查询方法public static void show(){System.out.println("姓名:" +name +" 卡号:" + id);System.out.println("你的余额为:" + balance);}}package src.day01;public class Welbank {/__* @param args*/public static void main(String[] args) {。

java银行账户管理系统

java银行账户管理系统

Java银行账户管理系统简介Java银行账户管理系统是一种基于Java语言开发的系统,旨在提供简便、高效的银行账户管理功能。

该系统可以帮助银行实现对账户信息的管理、存储和操作,包括创建新账户、存款、取款、转账等功能。

功能Java银行账户管理系统具有以下主要功能:1. 创建新账户用户可以通过系统来创建新的银行账户。

在创建过程中,系统会要求用户提供必要的信息,如账户类型、账户持有人姓名、初始存款金额等。

系统将生成唯一的账户ID,并将新账户添加到账户列表。

2. 存款已创建的账户可以通过系统进行存款操作。

用户需要选择要存款的账户,并输入存款金额。

系统将更新账户余额并记录存款操作日志。

3. 取款已创建的账户可以通过系统进行取款操作。

用户需要选择要取款的账户,并输入取款金额。

系统将检查账户余额是否足够,若余额充足则进行取款操作并记录取款日志。

4. 转账系统允许用户在已创建的账户之间进行转账操作。

用户需要选择要转出和转入的账户,并输入转账金额。

系统将检查转出账户余额是否足够,若余额充足则进行转账操作并记录转账日志。

5. 查询账户余额用户可以通过系统查询特定账户的余额信息。

系统将根据用户提供的账户ID,在账户列表中查找对应账户并返回余额信息。

6. 查询交易记录用户可以通过系统查询特定账户的交易记录。

系统将根据用户提供的账户ID,在交易记录列表中查找对应账户的所有交易记录,并按时间顺序返回。

实现细节Java银行账户管理系统的实现主要包括以下几个模块:1. 账户类账户类是系统的核心模块,用于表示一个银行账户。

该类包含以下属性:•账户ID:用于唯一标识一个账户,由系统自动生成。

•账户类型:表示账户的类型,如储蓄账户、支票账户等。

•账户持有人姓名:表示账户的持有人姓名。

•余额:表示账户的当前余额。

该类还包括以下方法:•存款:用于向账户存入指定金额,更新余额。

•取款:用于从账户中取出指定金额,更新余额。

•转账:用于将指定金额从当前账户转移到另一个账户。

原创java银行账户管理系统代码

原创java银行账户管理系统代码

原创Java银行账户管理系统代码
简介
本文档将介绍一个原创的Java银行账户管理系统代码。

该代码用于模拟一个简单的银行账户管理系统,包括账户的创建、存款、取款、查询余额等功能。

功能列表
•创建账户:根据用户输入的账户信息,创建新的银行账户。

•存款:将用户输入的金额存入指定账户。

•取款:从指定账户中取出用户指定的金额。

•查询余额:根据用户输入的账户信息,查询指定账户的余额。

开发工具和环境
•开发语言:Java
•开发环境:Eclipse IDE
•JDK版本:Java SE 8
代码实现
下面是代码的具体实现。

```java import java.util.HashMap; import java.util.Map; import java.util.Scanner;
public class BankAccountManagementSystem {
private static Map<String, Double> accountMap = new HashMap<>();
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
System.out.println(\。

Java-银行管理系统源代码

Java-银行管理系统源代码

Java 小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts {protected int id;// 银行账号protected String password;// 用户密码protected String name;// 用户型号protected String personId;// 身份账号protected int accountType;// 账号类型,0 代表储蓄卡, 1 代表信用卡protected double balance;// 账户余额。

之所以定义为protected 是让他的子类可以直接用,不需要通过方法来赋值。

protected double ceiling;public String getPassword(){return password;}public void setPassword(String password){this.password=password;}public String getName(){return name;}public void setName(String name){=name;}public String getPersonId(){return personId;}public void setPersonId(String personId){this.personId=personId;}public int getAccountType(){return accountType;}public void setAccountType(int accountType){this.accountType=accountType;}public double getBalance(){return balance;}public void setBalance(double balance){this.balance=balance;}public int getId(){return id;}public void setId(int id){this.id=id;}public double getCeiling(){return ceiling;}public void setCeiling(double ceiling){this.ceiling=ceiling;}// 无参数构造方法public accounts(){}// 构造方法public accounts(String password,String name,String personId,int accountType, double balance,double ceiling){super();this.password=password;=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}// 存款public void deposit(double money){balance+=money;}// 取款public void withdraw(double money){if(accountType==1){if((balance+ceiling)<money){System.out.println(" 对不起,已超出您的信用额度!");}else{balance-=money;}}else{if(balance<money){System.out.println(" 对不起,账户余额不足!");}else{balance-=money;}}}}DBoper.javapackage DB;import java.sql.*;import java.util.ArrayList;import Account.accounts;public class DBoper {private Connection conn = null;private Statement st = null;private PreparedStatement pstmt = null;private ResultSet rs = null;private ArrayList<accounts> result;// 连接数据库public Connection getConnection(){try{Class.forName("com.mysql.jdbc.Driver");conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bankmanager?useUnicode=true&characterEncoding=utf8","root","xuewei");}catch(Exception e){System.out.println(" 数据库连接失败");}return conn;}// 修改删除用户数据public boolean accountDataUpdate(String sql){conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();//System.out.println(" 数据更新成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();//System.out.println(" 更新失败");return false;}}// 依据id 来修改记录public boolean dataupdateid(accounts user, int id) {conn = getConnection();try {String sql = "update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=? where id="+ id;pstmt = conn.prepareStatement(sql);pstmt.setString(1, user.getName());pstmt.setString(2, user.getPassword());pstmt.setString(3, user.getPersonId());pstmt.setInt(4, user.getAccountType());pstmt.setDouble(5, user.getBalance());pstmt.setDouble(6, user.getCeiling());pstmt.executeUpdate();System.out.println(" 操作成功");return true;}catch (SQLException e) {e.printStackTrace();System.out.println(" 操作失败");return false;}}// 插入用户数据public boolean accountDataInsert(accounts account){conn=getConnection();try{pstmt=conn.prepareStatement("insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?)");pstmt.setString(1, account.getName());pstmt.setString(2, account.getPassword());pstmt.setString(3, account.getPersonId());pstmt.setInt(4, account.getAccountType());pstmt.setDouble(5, account.getBalance());pstmt.setDouble(6, account.getCeiling());pstmt.executeUpdate();System.out.println(" 新用户数据插入成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();System.out.println(" 插入失败");return false;}}// 查询数据public ResultSet dataquery(String sql) {conn = getConnection();try {pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();}catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return rs;}public ResultSet testlist() {try {String sql = "select * from account where id =1001";pstmt = conn.prepareStatement(sql);System.out.println(sql);rs = pstmt.executeQuery();} catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return rs;}public ArrayList<accounts> testt(int id) {ArrayList<accounts> list = new ArrayList<accounts>();conn = getConnection();try {String sql = "select * from account where id=" + id;pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next()) {accounts user = new accounts();user.setName(rs.getString("username"));user.setPassword(rs.getString("userpwd"));user.setPersonId(rs.getString("personId"));user.setAccountType(rs.getInt("accountType"));user.setBalance(rs.getDouble("balance"));user.setCeiling(rs.getDouble("ceiling"));list.add(user);}}catch (SQLException e) {e.printStackTrace();System.out.println(" 检索失败");}return list;}// 根据卡号和密码验证用户是否存在public boolean verify(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();if(rs.next()){return true;}else{return false;}}catch(SQLException e){e.printStackTrace();return false;}}/*** 登录验证*/public accounts verifyAccount(int id, String password) {boolean flag = verify(id, password);if(flag){accounts account=queryByIDandPassword(id, password);return account;}else{System.out.println(" 用户不存在!");return null;}}// 根据卡号和密码查询信息public accounts queryByIDandPassword(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}// 根据卡号查询信息public accounts queryByID(int id){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=?");pstmt.setInt(1, id);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}public static void main(String[] args) {// TODO Auto-generated method stubDBoper op=new DBoper();ArrayList<accounts> list=op.testt(1001);for(int i=0;i<list.size();i++){accounts user=new accounts();user=list.get(i);System.out.println(user.getName());System.out.println(user.getPassword());System.out.println(user.getPersonId());System.out.println(user.getAccountType());System.out.println(user.getBalance());System.out.println(user.getCeiling());}}}// 图像界面文件夹DN_SYSTEMDefault.java // 主界面package DN_SYSTEM;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionListener{accounts account=DN_ATM.client;DBoper db=new DBoper();private JFrame jf;private JButton btn0,btn1,btn2,btn3,btn4,btn5;private Container c;public void defaltDemo() {// 添加主界面卡片//DN_ATM.id;int id=DN_ATM.id;//account=db.queryByID(id);jf=new JFrame("DEFAULT");c=jf.getContentPane();c.setLayout(null);c.setBackground(new Color(119,119,253));JLabel lblwel = new JLabel("欢迎"+account.getName()+" 用达能银行ATM系统");lblwel.setBounds(20, 15, 350, 30);c.add(lblwel);JLabel lblwel1 = new JLabel("请选择您需要的交易类型");lblwel1.setBounds(120, 45, 350, 30);c.add(lblwel1);btn1 = new JButton(" 取款服务");btn1.addActionListener(this);btn1.setBounds(70, 90, 100, 30);c.add(btn1);btn2=new JButton(" 存款服务");btn2.addActionListener(this);btn2.setBounds(210, 90, 100, 30);c.add(btn2);btn3 = new JButton(" 查询余额");btn3.addActionListener(this);btn3.setBounds(70, 150, 100, 30);c.add(btn3);btn4 = new JButton(" 转账服务");btn4.addActionListener(this);btn4.setBounds(210, 150, 100, 30);c.add(btn4);btn5 = new JButton(" 注销账户");btn5.addActionListener(this);btn5.setBounds(70, 210, 100, 30);c.add(btn5);btn0 = new JButton(" 退出操作");btn0.addActionListener(this);btn0.setBounds(210, 210, 100, 30);c.add(btn0);jf.setVisible(true);jf.setResizable(false);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }// 事件处理@Overridepublic void actionPerformed(ActionEvent e){// 取款服务if(e.getSource().equals(btn1)){OutMoney outmoney=new OutMoney();outmoney.outMoney();jf.dispose();}// 存款服务if(e.getSource().equals(btn2)){InMoney inmoney=new InMoney();inmoney.InMoney();jf.dispose();}// 查询余额if(e.getSource().equals(btn3)){GetBalance getbalance=new GetBalance();getbalance.getBalance();jf.dispose();}// 转账服务if(e.getSource().equals(btn4)){TransferAccounts tranfer=new TransferAccounts();tranfer.transferAccounts();jf.dispose();}// 注销账户if(e.getSource().equals(btn5)){String sql="delete from account where id="+account.getId();boolean flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this," 注销成功!");}else{JOptionPane.showMessageDialog(this, " 注销失败!");}}if(e.getSource().equals(btn0)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDefault defaults=new Default();defaults.defaltDemo();}}DN_ATM.java // 功能界面package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.AbstractButton;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import DB.DBoper;import Account.accounts;public class DN_ATM extends JFrame implements ActionListener{ private JLabel lbljixu;private JButton btngetcard;private JButton btncard,btn010,btn_addAccount,btnsure,btnback;private JTextField txt1;private JPasswordField txt2;private Container container;private CardLayout Layout;private JLabel lblwrong;private JPanel panelfirst,panelmain;public static int id;static accounts client = null;public DN_ATM(){super("达能银行");this.setSize(435, 350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 设置不可改变窗口大小this.setResizable(false);}// 布局public void setLayout(){// 用卡片布局Layout = new CardLayout();container = getContentPane();container.setLayout(Layout);// 添加第一张卡片panelfirst = new JPanel(null);// 设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu = new JLabel(" 请放入磁卡,然后继续操作");// 设置卡片在Panel 中的位置lbljixu.setBounds(140, 90, 350, 30);// 为第一张卡片添加一个Labelpanelfirst.add(lbljixu);// 为第一张卡片添加一个按钮btncard = new JButton(" 继续");btncard.setBounds(310, 180, 80, 30);// 为按钮注册事件监听器btncard.addActionListener(this);// 开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);// 为第一张卡片添加一个按钮btngetcard = new JButton(" 取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310, 220, 80, 30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);// 添加登录输入卡片panelmain = new JPanel(null);panelmain.setBackground(new Color(119,119,253));// 添加登录输入卡号JLabel lblnumber = new JLabel("请输入您的银行卡卡号:"); panelmain.add(lblnumber);lblnumber.setBounds(30, 30, 150, 30);// 设置文本框为密码型txt1 = new JTextField(12);// 文本框不可选中//txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170, 30, 200, 30);JLabel lblpwd = new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(30, 80, 150, 30);// 设置文本框为密码型txt2 = new JPasswordField(12);// 文本框不可选中//txt2.enable(false);panelmain.add(txt2);// 文本框的输入内容用* 显示txt2.setEchoChar('*');txt2.setBounds(170, 80, 200, 30);// 添加选择按钮btnsure = new JButton(" 确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70, 160, 80, 30);// 添加重输按钮btn010 = new JButton(" 重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback = new JButton(" 退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280, 160, 80, 30);// 开户btn_addAccount = new JButton(" 开户");btn_addAccount.setBounds(70, 220, 80, 30);btn_addAccount.addActionListener(this);panelmain.add(btn_addAccount);lblwrong = new JLabel(" 请注意保护好您的密码!");panelmain.add(lblwrong);lblwrong.setBounds(180, 110, 200, 30);container.add(panelmain, "main");}// 事件处理@SuppressWarnings("deprecation")@Overridepublic void actionPerformed(ActionEvent e){DBoper db=new DBoper();if(e.getSource().equals(btn_addAccount)){OpenAccount open=new OpenAccount();open.adduser();}// 磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure)){client = db.verifyAccount(Integer.parseInt(txt1.getText()), txt2.getText());if(client!=null){Default defa=new Default();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText());txt1.setText("");txt2.setText("");}else{lblwrong.setText(" 卡号或密码不正确,请重新输入!");txt1.setText("");txt2.setText("");}}// 重置输入卡号和密码if(e.getSource()==btn010){txt1.setText("");txt2.setText("");lblwrong.setText(" 请注意保护好您的密码!");}// 退出if(e.getSource().equals(btnback)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDN_ATM ATM=new DN_ATM();ATM.setLayout();ATM.setVisible(true);}}GetBalance.java // 查询余额package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class GetBalance extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JLabel lblremain1,lblremain;private JButton btnremain,btnremain1;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;// 添加查询余额界面卡片public void getBalance(){account=db.queryByID(id);jf=new JFrame("FIND DALANCE");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(new Color(119,119,253));lblremain1 = new JLabel(" 尊敬的达能用户您好!");lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain = new JLabel(" 请点击继续操作查询余额:");lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain = new JButton(" 继续操作");btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1 = new JButton(" 退出操作");btnremain1.setBounds(200,150,90,30);btnremain1.addActionListener(this);c.add(btnremain1);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){// 查询余额if(e.getSource()==btnremain){lblremain1.setText(" 卡号:"+account.getId()+" 用户名:"+account.getName());lblremain.setText(" 您的余额为"+account.getBalance()+" 元,是否继续操作?");}if(e.getSource()==btnremain1){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubGetBalance balance=new GetBalance();balance.getBalance();}}InMoney.java // 存款package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class InMoney extends JFrame implements ActionListener{private JLabel lblsave,lblsave1;private JButton btnsave,btnsave2;private JTextField txt2;private double savemoney ;private double lastmoney;private boolean flag;private JFrame jf;private Container c;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void InMoney(){account=db.queryByID(id);jf=new JFrame("IN MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);// 添加存款显示界面卡片c.setBackground(new Color(119,119,253));lblsave = new JLabel("请在存款口处放入存款");lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1 = new JLabel("请注意:只接收100 元或100 元的整数倍存款");lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2 = new JTextField(12);c.add(txt2);txt2.setBounds(95, 80, 200, 30);btnsave = new JButton(" 放入存款完毕");btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2 = new JButton(" 返回");btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btnsave2);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btnsave){savemoney=Double.parseDouble(txt2.getText());lastmoney=account.getBalance();lastmoney+=savemoney;String sql = "update account set balance="+lastmoney+"where id="+ id;flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this, " 存款成功!");txt2.setText("");Default defa=new Default();defa.defaltDemo();jf.dispose();}else{JOptionPane.showMessageDialog(this, " 存款失败!");}}if(e.getSource()==btnsave2){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubInMoney inmoney=new InMoney();inmoney.InMoney();}}OpenAccount.java // 开户package DN_SYSTEM;import ponent;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.WindowConstants;import DB.DBoper;import Account.accounts;public class OpenAccount extends JFrame implements ActionListener{private JFrame jf;private Container c;private JTextField txtname,txt_personId;private JPasswordField txtpwd,txtpwd1;private JRadioButton rbt1;private JRadioButton rbt2;String accountType;// 开户,增加新用户public void adduser(){jf=new JFrame("Open Account");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);JLabel lbname=new JLabel("用户名:");lbname.setBounds(100, 40, 80, 20);txtname=new JTextField();txtname.setBounds(160, 40, 130, 20);c.add(lbname);c.add(txtname);JLabel lbpwd=new JLabel("密码:");lbpwd.setBounds(110, 65, 80, 20);txtpwd=new JPasswordField();txtpwd.setBounds(160, 65, 130, 20);txtpwd.setEchoChar('*');c.add(lbpwd);c.add(txtpwd);JLabel lbpwd1=new JLabel("确认密码:");lbpwd1.setBounds(86, 90, 80, 20);txtpwd1 = new JPasswordField();txtpwd1.setBounds(160, 90, 130, 20);txtpwd1.setEchoChar('*');c.add(lbpwd1);c.add(txtpwd1);JLabel lbpersonId=new JLabel("身份证号:");lbpersonId.setBounds(86, 115, 80, 20);txt_personId = new JTextField();txt_personId.setBounds(160, 115, 130, 20);c.add(lbpersonId);c.add(txt_personId);JLabel lbtype=new JLabel("账户类型:");lbtype.setBounds(86, 120, 80, 60);rbt1=new JRadioButton(" 信用卡");rbt1.setBounds(160, 135, 70, 30);rbt2=new JRadioButton(" 储蓄卡");rbt2.setBounds(225, 135, 70, 30);ButtonGroup group=new ButtonGroup();group.add(rbt2);group.add(rbt1);c.add(lbtype);c.add(rbt2);c.add(rbt1);JButton btnsubmit=new JButton(" 提交");btnsubmit.setBounds(100, 190, 80, 20);JButton btnreset=new JButton(" 重置");btnreset.setBounds(205, 190, 80, 20);c.add(btnsubmit);c.add(btnreset);btnsubmit.addActionListener(this);btnreset.addActionListener(this);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }public static void main(String[] args) {// TODO Auto-generated method stubOpenAccount openA=new OpenAccount();openA.adduser();}@Overridepublic void actionPerformed(ActionEvent e){accounts account=new accounts();account.setName(txtname.getText());if(txtpwd.getText().equals(txtpwd1.getText())){account.setPassword(txtpwd.getText());}else{JOptionPane.showMessageDialog(this," 两次输入的密码不一致,请重新输入!");}account.setPersonId(txt_personId.getText());if(rbt1.isSelected())accountType="1";if(rbt2.isSelected())accountType="0";account.setAccountType(Integer.parseInt(accountType));account.setBalance(0);if(accountType.equals("1")){account.setCeiling(5000.0);}else{account.setCeiling(0);}DBoper db=new DBoper();if(db.accountDataInsert(account)){JOptionPane.showMessageDialog(this," 开户成功!");jf.dispose();// 关闭当前登录窗体return;}else{JOptionPane.showMessageDialog(this," 开户失败!");return;}}}OutMoney.java // 取款package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class OutMoney extends JFrame implements ActionListener{private JFrame jf;private JButton btn100,btn200,btn300,btn500,btn1000;private JButton btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn000;private JButton btnsure1,btn0010,btnback2;private JTextField txt2;private Container c;private JLabel lblqukuan;private int money;private double lastmoney;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void outMoney(){account=db.queryByID(id);jf=new JFrame("OUT MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);// 添加取款页面卡片//panel4=new JPanel(null);c.setBackground(new Color(119,119,253));lblqukuan = new JLabel(" 请输入您的取款金额:");c.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel(" 提示:只能是100 元或100 元的整数倍");c.add(lblqukuan);lblqukuan.setBounds(115, 50, 300, 30);txt2 = new JTextField(12);txt2.enable(false);c.add(txt2);txt2.setBounds(115, 90, 200, 30);btn100 = new JButton("100");c.add(btn100);btn100.addActionListener(this);btn100.setBounds(45, 190, 60, 30);btn200 = new JButton("200");c.add(btn200);btn200.addActionListener(this);btn200.setBounds(115, 190, 60, 30);btn300 = new JButton("300");c.add(btn300);btn300.addActionListener(this);btn300.setBounds(185, 190, 60, 30);btn500 = new JButton("500");btn500=new JButton("500");c.add(btn500);btn500.addActionListener(this);btn500.setBounds(255, 190, 60, 30);btn1000 = new JButton("1000");c.add(btn1000);btn1000.addActionListener(this);btn1000.setBounds(325, 190, 65, 30);btn001 = new JButton("1");c.add(btn001);btn001.addActionListener(this);btn001.setBounds(45, 230, 60, 30);btn002 = new JButton("2");c.add(btn002);btn002.addActionListener(this); btn002.setBounds(115, 230, 60, 30);btn003 = new JButton("3");c.add(btn003);btn003.addActionListener(this); btn003.setBounds(185, 230, 60, 30);btn004 = new JButton("4");c.add(btn004);btn004.addActionListener(this); btn004.setBounds(255, 230, 60, 30);btn005 = new JButton("5");c.add(btn005);btn005.addActionListener(this); btn005.setBounds(325, 230, 65, 30);btn006 = new JButton("6");c.add(btn006);btn006.addActionListener(this); btn006.setBounds(45, 270, 60, 30);btn007 = new JButton("7");c.add(btn007);btn007.addActionListener(this); btn007.setBounds(115, 270, 60, 30);btn008 = new JButton("8");c.add(btn008);btn008.addActionListener(this); btn008.setBounds(185, 270, 60, 30);btn009 = new JButton("9");c.add(btn009);btn009.addActionListener(this); btn009.setBounds(255, 270, 60, 30);btn000 = new JButton("0");c.add(btn000);btn000.addActionListener(this); btn000.setBounds(325, 270, 65, 30);btnsure1 = new JButton(" 确定");。

银行管理系统源代码

银行管理系统源代码

银行管理系统源代码#include#include#includeusing namespace std;class user; //声明用户类class yinhang{ //银行类public:void set_account();//开户函数void del_account();//销户函数void transfer_accounts(int a);//转账函数void enter();//登录函数void menu();//菜单函数void exit_yinhang();//退出函数void save();void load();protected:static int amount;//静态成员,用于统计银行账户数user *account[100];//账户数};int yinhang::amount=0;//静态成员赋值,初始为0 class user:public yinhang{ //用户类private:string id;//账号string mm;//密码string name;//姓名double balance;//余额string identity_card;//身份证string unit;//单位string phone;//电话号码string address;//地址public:user()//不带参数的构造函数{id='0';mm='0';name='0';balance=0;identity_card='0';unit='0';phone='0';address='0';}user(string id1,string mm1,string name1,double balance1,string identity_card1,string unit1,string phone1,string address1) //带参数的构造函数id=id1;mm=mm1;name=name1;balance=balance1;identity_card=identity_card1;unit=unit1;phone=phone1;address=address1;}friend class yinhang;//声明yinhang类是user的友元类void save_money();//存钱函数void fetch_money();//取钱函数void show()//显示函数{system("cls");cout<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl<<endl<<="" p="">cout<<" 姓名:"<<name<<endl;< p="">cout<<" 账号:"<<id<<endl;< p="">cout<<" 余额:"<<balance<<endl;< p="">cout<<" 身份证:"<<identity_card<<endl;< p="">cout<<" 单位:"<<unit<<endl;< p="">cout<<" 电话号码:"<<phone<<endl;< p="">cout<<" 地址:"<<address<<endl<<endl<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl;< p="">}string get_id()//取得账号{return id;}string get_mm()// 取得密码{return mm;}int get_balance()//取得余额{return balance;}void add_money(double x)//通过公有成员函数访问私有成员{balance=x+balance;void dec_money(double x){balance=balance-x;}};void yinhang::save(){ofstream o("g:\\C++\\祁鹏涛\\银行账户信息.txt",ios::out); int n=0;for(n=0;n<amount;n++)< p="">{o<id<<="">o<mm<<endl;< p="">o<name<<endl;< p="">o<balance<<endl;< p="">o<identity_card<<endl;< p="">o<unit<<endl;< p="">o<phone<<endl;< p="">o<address<<endl;< p="">}o.close();}void yinhang::load(){ifstream i("g:\\c++\\祁鹏涛\\银行账户信息.txt",ios::in); int n;for(n=0;n<amount;n++)< p="">{i>>account[n]->id;//读取账号i>>account[n]->mm;i>>account[n]->name;i>>account[n]->balance;i>>account[n]->identity_card;i>>account[n]->unit;i>>account[n]->phone;i>>account[n]->address;}i.close();}void yinhang::set_account() //开户函数的定义{string id1;string mm1;string name1;double balance1;string identity_card1;string unit1;string phone1;string address1;cout<<"请输入开户人账号:";cin>>id1;int m=0;for(int i=0;i<amount;i++)< p="">{if(id1==account[i]->get_id()){m=1;}}if(m)cout<<"本账号已经存在!"<<endl;< p="">return;}cout<<"请输入密码:";cin>>mm1;cout<<"请输入姓名:";cin>>name1;cout<<"请输入存入金额:";cin>>balance1;while(balance1<0){cout<<"请输入正确的数字!"<<endl;< p="">cout<<"请重新输入:";cin>>balance1;}cout<<"请输入开户人身份证:";cin>>identity_card1;cout<<"请输入工作单位:";cin>>unit1;cout<<"请输入电话号码:";cin>>phone1;cout<<"请输入地址:";cin>>address1;cout<<"开户成功!"<<endl;< p="">user *u=new user(id1,mm1,name1,balance1,identity_card1,unit1,phone1,addr ess1); account[amount]=u;amount++;save();void yinhang::del_account() //销户函数的定义{string id1;int i=0;int m=1;cout<<"请输入需要注销的银行卡号:";cin>>id1;while((i<amount)&&(m)) p="" 从0开始进行依次检索,判断id1与其中的一个账号是否相等<="">{if(id1==account[i]->get_id())m=0;elsei++;}if(m){cout<<" 该帐号不存在!"<<endl;< p="">return;}for(int j=i;j<amount;j++)< p="">{account[j]=account[j+1];}account[amount-1]=NULL;amount=amount-1;cout<<"你的银行账户已经注销成功!"<<endl;< p="">save();}void yinhang::transfer_accounts(int x) //转账函数的定义{string id1;cout<<"请输入帐号:";cin>>id1;int m=1;int i=0;while((i<amount)&&(m))< p="">{if(id1==account[i]->get_id())m=0;elsei++;}if(m){cout<<"帐号不存在!"<<endl;< p="">return;}double b;cout<<"请输入你要转帐的金额:";cin>>b;while(b<=0){cout<<"请输入正确的数字!"<<endl;< p="">cout<<"请输入:";cin>>b;}if(account[x]->get_balance()<b)< p="">cout<<"对不起,金额不够!!"<<endl;< p="">{account[x]->dec_money(b);account[i]->add_money(b);cout<<"转账成功!"<<endl;< p="">}return;}void yinhang::enter() //登录函数{string id1;cout<<"请输入银行账号:";cin>>id1;int m=1;int i=0;while((i<amount)&&(m))< p=""> {if(id1==account[i]->get_id())m=0;elsei++;}if(m){cout<<"帐号不存在!"<<endl;< p=""> return;cout<<"请输入密码:";string mm1;cin>>mm1;if(mm1!=account[i]->get_mm()) return;cout<<"登录成功,请选择下列操作:"<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl<<endl<<endl;< p="">cout<<" 1.查看账户信息"<<endl<<endl;< p="">cout<<" 2.取款"<<endl<<endl;< p="">cout<<" 3.存款"<<endl<<endl;< p="">cout<<" 4.转账"<<endl<<endl;< p="">cout<<" 5.退出本次登录"<<endl<<endl<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl;< p="">int n;cout<<"请选择:";cin>>n;system("cls");switch(n){case 1: account[i]->show();system("pause");break;case 2: account[i]->fetch_money();save();system("pause");break;case3:account[i]->save_money();save();system("pause");break;case 4:transfer_accounts(i);save();system("pause");break;case 5:return;}}while(1);}void yinhang::exit_yinhang() //退出系统{cout<<"欢迎下次光临!"<<endl;< p="">exit(0);}void user::save_money() //存款函数{double m;cout<<"请输入存款金额:";cin>>m;while(m<=0){cout<<"请输入正确的数字!"<<endl;< p=""> cin>>m;balance=balance+m;cout<<"存款成功!"<<endl;< p="">}void user::fetch_money() //取款函数{double m;cout<<"请输入取款金额:"<<="" p="">cin>>m;while(m<=0){cout<<"请输入正确的数字!"<<endl;< p=""> cin>>m;}if(balance<m)< p="">cout<<"对不起,你的余额已不足!"<<endl;< p=""> else{balance=balance-m;cout<<"取款成功!"<<endl;< p="">}}void yinhang::menu(){do{load();cout<<endl;< p="">cout<<" 欢迎光临"<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl<<endl;< p="">cout<<" 1.开户"<<endl;< p="">cout<<" 2.登录"<<endl;< p="">cout<<" 3.注销"<<endl;< p="">cout<<" 4.退出"<<endl<<endl;< p="">cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<en dl;< p="">int n;cout<<"请选择:";cin>>n;system("cls");switch(n){case 1:set_account();system("pause");//开户break;case 2:enter();system("pause");//登录break;case 3:del_account();system("pause");//注销break;case 4:exit_yinhang();system("pause");//退出break;}}while(1);}void main(){yinhang yh;yh.menu();}</endl;<></endl<<endl;<></endl;<></endl;<></endl;<></endl<<endl;<></endl;<></endl;<></endl;<></endl;<></m)<></endl;<></endl;<></endl;<></endl;<></endl;<></endl<<endl<<endl;<> </endl<<endl;<></endl<<endl;<></endl<<endl;<></endl<<endl<<endl;<></endl;<></endl;<></amount)&&(m))<></endl;<></endl;<></b)<></endl;<></endl;<></amount)&&(m))<></endl;<></amount;j++)<></endl;<></amount)&&(m))></endl;<></endl;<></endl;<></amount;i++)<></amount;n++)<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></amount;n++)<></endl;<></address<<endl<<endl<<endl;<></unit<<endl;<></identity_card<<endl;<> </balance<<endl;<></id<<endl;<></name<<endl;<></endl<<endl<</endl;<>。

小型银行管理系统的功能代码

小型银行管理系统的功能代码

小型银行管理系统的部分代码登陆package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import java.sql.*;public class login{private String sName;private String sPass;private String sState;//数据库连接设立protected static String dbClassName = "com.mysql.jdbc.Driver";protected static String dbUrl = "jdbc:mysql://localhost:3306/bank";protected static String dbUser = "root";protected static String dbPwd = "root";private static Connection conn = null;public String getsName() {return sName;}public void setsName(String sName) { this.sName = sName;}public String getsPass() {return sPass;}public void setsSPass(String sPass) { this.sPass = sPass;}public String getsState() {return sState;}public void setsState(String sState) { this.sState = sState;}/*** 创建数据库连接**/private void NewConnect(){try {if (conn == null) {Class.forName(dbClassName).newInstance();conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);}elsereturn;} catch (Exception ee) {ee.printStackTrace();}}public List stuSearch(){String sql="select * from person where name='"+sName+"' and pass='"+sPass+"' and state='"+sState+"'";// System.out.println(sql);List list=new ArrayList();ResultSet rs = null;try {if(conn==null) N ewConnect();//假如数据库连接为空, 则创建rs = conn.createStatement().executeQuery(sql);} catch (SQLException e) {e.printStackTrace();}try {//通过循环, 将数据结果集中的内容取出while(rs.next()){login ep = new login();ep.setsName(ep.getsName());ep.setsSPass(ep.getsPass());ep.setsState(ep.getsState());// System.out.println(ep.getsName()+ep.getsPass()+ep.getsState());list.add(ep);}} catch (SQLException e) {// TODO 自动生成catch 块e.printStackTrace();}return list;//查询结果, 数组返回}}数据库package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class shujuku {public shujuku(String sql){//接受一个SQL语句并执行try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();stmt.executeUpdate(sql);stmt.close();}catch(Exception e){e.printStackTrace();}}}数据package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class shuju {public static String shuj(){//查询出账户的最大值并返回这个最大值供其他方法调用String s=null;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery("select max(cid) as cid from `Bank`.`yonghuxinxi` ");while(rs.next())s=rs.getString("cid");stmt.close();rs.close();}catch(Exception e){e.printStackTrace();}return s;}}数据库连接package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import java.util.Vector;import java.sql.*;public class Employee {private String ename;private String eid;private String eaddr;private String esalary;private String epassward;private String esex;private String etel;//数据库连接设立protected static String dbClassName = "com.mysql.jdbc.Driver";protected static String dbUrl = "jdbc:mysql://localhost:3306/bank";protected static String dbUser = "root";protected static String dbPwd = "root";private static Connection conn = null;public String getename() {return ename;}public void setename(String ename) {this.ename = ename;}public String geteid() {return eid;}public void seteid(String eid) {this.eid = eid;}public String geteaddr() {return eaddr;}public void seteaddr(String eaddr) { this.eaddr = eaddr;}public String getesalary() {return esalary;}public void setesalary(String esalary) { this.esalary = esalary;}public String getepassward() {return epassward;}public void setepassward(String epassward) { this.epassward = epassward;}public String getesex() {return esex;}public void setesex(String esex) {this.esex = esex;}public String getetel() {return etel;}public void setetel(String etel) {this.etel = etel;}/*** 创建数据库连接**/private void NewConnect(){try {if (conn == null) {Class.forName(dbClassName).newInstance();conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);}elsereturn;} catch (Exception ee) {ee.printStackTrace();}}/*** 增长员工* @param stu*/public void AddEmployee(){//拼装插入员工信息的SQL语句String ssql="insert into employee(name,id,addr,salary,passward,sex,tel) values ("+ "'"+this.ename+"',"+"'"+this.eid+"',"+"'"+this.eaddr+"',"+"'"+this.esalary+"',"+"'"+this.epassward+"',"+"'"+this.esex+"',"+"'"+this.etel+"')";System.out.println(ssql);try {if(conn==null) NewConnect();//假如数据库连接为空, 则创建//执行SQL语句, 插入员工信息conn.createStatement().executeUpdate(ssql);} catch (SQLException e) {e.printStackTrace();}}/*** 删除员工* @param stu*/public void DelEmployee(){//拼装删除员工的SQL语句String ssql="delete from employee where id ='"+this.eid+"'";try {if(conn==null) NewConnect();//假如数据库连接为空, 则创建//执行SQL语句, 删除员工信息conn.createStatement().executeUpdate(ssql);} catch (SQLException e) {e.printStackTrace();}}/*** 员工查询* @param x* @return*/public Vector<Vector> stuSearch(){//拼装查询员工的SQL语句String sql="select name,id,addr,salary,passward,sex,tel from employee";//假如姓名非空, 则将姓名作为查询条件if(this.ename!=null){sql+=" where name='"+this.ename+"'";}//假如性别非空, 则将性别作为查询条件Vector<Vector> v =new Vector<Vector>();//List list=new ArrayList();ResultSet rs = null;try {if(conn==null) N ewConnect();//假如数据库连接为空, 则创建//执行查询, 查询结果保存在数据结果集rs中//rs = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDA TABL E).executeQuery(sql);rs = conn.createStatement().executeQuery(sql);} catch (SQLException e) {e.printStackTrace();}try {//通过循环, 将数据结果集中的内容取出while(rs.next()){//每一条员工记录作为一个对象, 加入到数组中/*Employee stuinfo = new Employee();stuinfo.setename(rs.getString("name"));stuinfo.seteid(rs.getString("id"));stuinfo.setesex(rs.getString("sex"));stuinfo.setesalary(rs.getString("salary"));stuinfo.setepassward(rs.getString("passward"));stuinfo.seteaddr(rs.getString("addr"));stuinfo.setetel(rs.getString("tel"));*/Vector<String> ve = new V ector<String>();for(int i = 1;i<8;i++){ve.add(rs.getString(i));}v.add(ve);}} catch (SQLException e) {// TODO 自动生成catch 块e.printStackTrace();}return v;//查询结果, 员工信息数组返回}}开户package dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;public class Cxshuju {public static int cxshuj(String s,String ss){//判断用户输入的账户、密码是否对的, 假如对的返回1,否则返回0int a=0;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery("select * from bank.yonghuxinxi");while(rs.next())if (rs.getString("cid").equals(s) && rs.getString("mm").equals(ss)){a=1;break;}stmt.close();rs.close();}catch(Exception e){e.printStackTrace();}return a;public static int cxshuj(String s){//判断数据库中是否存在账户名s,若存在返回1,否则返回0int a=0;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery("select * from bank.yonghuxinxi");while(rs.next())if (rs.getString("cid").equals(s)){a=1;break;}stmt.close();rs.close();}catch(Exception e){e.printStackTrace();}return a;public static String cxsj(String s){//查询余额String a=null;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery(s);while(rs.next())a=rs.getString("je");rs.close();stmt.close();}catch(Exception e){e.printStackTrace();}return a;}public static String cxsju(String s){//查询身份证号String a=null;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery(s);while(rs.next())a=rs.getString("sid");rs.close();stmt.close();}catch(Exception e){e.printStackTrace();}return a;}public static String chaxsj(String s){//查询历史信息String a="";try{String a1=null,a2=null,a3=null,a4=null,a5=null,a6=null;Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://localhost/Bank?useUnicode=true&characterEncoding=GBK";Connection con=DriverManager.getConnection(url,"root","root");Statement stmt=con.createStatement();ResultSet rs=stmt.executeQuery(s);while(rs.next()){a1=rs.getString("cid");a2=rs.getString("sid");a3 = rs.getString("je");a4 = rs.getString("cun");a5=rs.getString("qu");a6=rs.getString("date");String a0=" 卡号: "+a1+" 身份证号: "+a2+" 金额: "+a3+" 存入: "+a4+" 取出: "+a5+" 日期: "+a6;a=a+a0+"\n\n";}rs.close();stmt.close();}catch(Exception e){e.printStackTrace();}return a;}}。

Java银行管理系统源代码

Java银行管理系统源代码

Java小型银行管理系统源代码(图形界面)accounts.javapackageAccount;publicclassaccounts{protectedintid;//银行账号protectedStringpassword;//用户密码protectedStringname;//用户型号protectedStringpersonId;//身份账号protectedintaccountType;//账号类型,0代表储蓄卡,1代表信用卡protecteddoublebalance;//账户余额。

之所以定义为protected是让他的子类可以直接用,不需要通过方法来赋值。

protecteddoubleceiling;publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){=name;}publicStringgetPersonId(){returnpersonId;}publicvoidsetPersonId(StringpersonId){ this.personId=personId;}publicintgetAccountType(){returnaccountType;}publicvoidsetAccountType(intaccountType){ this.accountType=accountType;}publicdoublegetBalance(){returnbalance;}publicvoidsetBalance(doublebalance){ this.balance=balance;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicdoublegetCeiling(){returnceiling;}publicvoidsetCeiling(doubleceiling){this.ceiling=ceiling;}//无参数构造方法publicaccounts(){}//构造方法publicaccounts(Stringpassword,Stringname,StringpersonId,intaccountType, doublebalance,doubleceiling){super();this.password=password;=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}//存款publicvoiddeposit(doublemoney){balance+=money;}//取款publicvoidwithdraw(doublemoney){if(accountType==1){if((balance+ceiling)<money){对不起,已超出您的信用额度!");}else{balance-=money;}}else{if(balance<money){对不起,账户余额不足!");}else{balance-=money;}}}}DBoper.javapackageDB;importjava.sql.*;importimportAccount.accounts; publicclassDBoper{privateConnectionconn=null; privateStatementst=null; privatePreparedStatementpstmt=null; privateResultSetrs=null; privateArrayList<accounts>result; //连接数据库publicConnectiongetConnection(){ try{Class.forName(conn=}catch(Exceptione){数据库连接失败");}returnconn;}//修改删除用户数据publicbooleanaccountDataUpdate(Stringsql){ conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();数据更新成功");conn.close();returntrue;}catch(SQLExceptione){e.printStackTrace();更新失败");returnfalse;}}//依据id来修改记录publicbooleandataupdateid(accountsuser,intid){conn=getConnection();try{Stringsql="updateaccountsetusername=,userpwd=,personId=,accountType=,balan ce=,ceiling=whereid="+id;pstmt=conn.prepareStatement(sql);pstmt.setString(1,user.getName());pstmt.setString(2,user.getPassword());pstmt.setString(3,user.getPersonId());pstmt.setInt(4,user.getAccountType());pstmt.setDouble(5,user.getBalance());pstmt.setDouble(6,user.getCeiling());pstmt.executeUpdate();操作成功");returntrue;}catch(SQLExceptione){e.printStackTrace();操作失败");returnfalse;}}//插入用户数据publicbooleanaccountDataInsert(accountsaccount){conn=getConnection();try{pstmt=conn.prepareStatement("insertintoaccount(username,userpwd,personId,a ccountType,balance,ceiling)values(,,,,,)");pstmt.setString(1,account.getName());pstmt.setString(2,account.getPassword());pstmt.setString(3,account.getPersonId());pstmt.setInt(4,account.getAccountType());pstmt.setDouble(5,account.getBalance());pstmt.setDouble(6,account.getCeiling());pstmt.executeUpdate();新用户数据插入成功");conn.close();returntrue;}catch(SQLExceptione){e.printStackTrace();插入失败");returnfalse;}}//查询数据publicResultSetdataquery(Stringsql){conn=getConnection();try{pstmt=conn.prepareStatement(sql);rs=pstmt.executeQuery();}catch(SQLExceptione){e.printStackTrace();检索失败");}returnrs;}publicResultSettestlist(){try{Stringsql="select*fromaccountwhereid=1001";pstmt=conn.prepareStatement(sql);sql);rs=pstmt.executeQuery();}catch(SQLExceptione){e.printStackTrace();检索失败");}returnrs;}publicArrayList<accounts>testt(intid){ArrayList<accounts>list=newArrayList<accounts>();conn=getConnection();try{Stringsql="select*fromaccountwhereid="+id;pstmt=conn.prepareStatement(sql);rs=pstmt.executeQuery();while(rs.next()){accountsuser=newaccounts();user.setName(rs.getString("username"));user.setPassword(rs.getString("userpwd"));user.setPersonId(rs.getString("personId"));user.setAccountType(rs.getInt("accountType"));user.setBalance(rs.getDouble("balance"));user.setCeiling(rs.getDouble("ceiling"));list.add(user);}}catch(SQLExceptione){e.printStackTrace();检索失败");}returnlist;}//根据卡号和密码验证用户是否存在publicbooleanverify(intid,Stringpassword){conn=getConnection();try{pstmt=conn.prepareStatement("select*fromaccountwhereid=anduserpwd=");pstmt.setInt(1,id);pstmt.setString(2,password);rs=pstmt.executeQuery();if(rs.next()){returntrue;}else{returnfalse;}}catch(SQLExceptione){e.printStackTrace();returnfalse;}}/***登录验证*/publicaccountsverifyAccount(intid,Stringpassword){ booleanflag=verify(id,password);if(flag){accountsaccount=queryByIDandPassword(id,password);returnaccount;}else{用户不存在!");returnnull;}}//根据卡号和密码查询信息publicaccountsqueryByIDandPassword(intid,Stringpassword){ conn=getConnection();try{pstmt=conn.prepareStatement("select*fromaccountwhereid=anduserpwd=");pstmt.setInt(1,id);pstmt.setString(2,password);rs=pstmt.executeQuery();accountsaccount=newaccounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}returnaccount;}catch(SQLExceptione){e.printStackTrace();returnnull;}}//根据卡号查询信息publicaccountsqueryByID(intid){conn=getConnection();try{pstmt=conn.prepareStatement("select*fromaccountwhereid=");pstmt.setInt(1,id);rs=pstmt.executeQuery();accountsaccount=newaccounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}returnaccount;}catch(SQLExceptione){e.printStackTrace();returnnull;}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubDBoperop=newDBoper();ArrayList<accounts>list=op.testt(1001);for(inti=0;i<list.size();i++){accountsuser=newaccounts();user=list.get(i);user.getName());user.getPassword());user.getPersonId());user.getAccountType());user.getBalance());user.getCeiling());}}}//图像界面文件夹DN_SYSTEMDefault.java//主界面packageDN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportAccount.accounts;importDB.DBoper; publicclassDefaultextendsJFrameimplementsActionListener{accountsaccount=DN_ATM.client;DBoperdb=newDBoper();privateJFramejf;privateJButtonbtn0,btn1,btn2,btn3,btn4,btn5;privateContainerc;publicvoiddefaltDemo(){//添加主界面卡片//DN_ATM.id;intid=DN_ATM.id;//account=db.queryByID(id);jf=newJFrame("DEFAULT");c=jf.getContentPane();c.setLayout(null);c.setBackground(newColor(119,119,253));JLabellblwel=newJLabel("欢迎"+account.getName()+"用达能银行ATM系统");lblwel.setBounds(20,15,350,30);c.add(lblwel);JLabellblwel1=newJLabel("请选择您需要的交易类型"); lblwel1.setBounds(120,45,350,30);c.add(lblwel1);btn1=newJButton("取款服务");btn1.addActionListener(this);btn1.setBounds(70,90,100,30);c.add(btn1);btn2=newJButton("存款服务");btn2.addActionListener(this);btn2.setBounds(210,90,100,30);c.add(btn2);btn3=newJButton("查询余额");btn3.addActionListener(this);btn3.setBounds(70,150,100,30);c.add(btn3);btn4=newJButton("转账服务");btn4.addActionListener(this);btn4.setBounds(210,150,100,30);c.add(btn4);btn5=newJButton("注销账户");btn5.addActionListener(this);btn5.setBounds(70,210,100,30);c.add(btn5);btn0=newJButton("退出操作");btn0.addActionListener(this);btn0.setBounds(210,210,100,30);c.add(btn0);jf.setVisible(true);jf.setResizable(false);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}//事件处理@OverridepublicvoidactionPerformed(ActionEvente){ //取款服务if(e.getSource().equals(btn1)){OutMoneyoutmoney=newOutMoney();outmoney.outMoney();jf.dispose();}//存款服务if(e.getSource().equals(btn2)){InMoneyinmoney=newInMoney();inmoney.InMoney();jf.dispose();}//查询余额if(e.getSource().equals(btn3)){GetBalancegetbalance=newGetBalance();getbalance.getBalance();jf.dispose();}//转账服务if(e.getSource().equals(btn4)){TransferAccountstranfer=newTransferAccounts();tranfer.transferAccounts();jf.dispose();}//注销账户if(e.getSource().equals(btn5)){Stringsql="deletefromaccountwhereid="+account.getId();booleanflag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this,"注销成功!");}else{JOptionPane.showMessageDialog(this,"注销失败!");}}if(e.getSource().equals(btn0)){System.exit(0);}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubDefaultdefaults=newDefault();defaults.defaltDemo();}}DN_ATM.java //功能界面packageDN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimportimportimportDB.DBoper;importAccount.accounts;publicclassDN_ATMextendsJFrameimplementsActionListener{ privateJLabellbljixu;privateJButtonbtngetcard;privateJButtonbtncard,btn010,btn_addAccount,btnsure,btnback;privateJTextFieldtxt1;privateJPasswordFieldtxt2;privateContainercontainer;privateCardLayoutLayout;privateJLabellblwrong;privateJPanelpanelfirst,panelmain;publicstaticintid;staticaccountsclient=null;publicDN_ATM(){super("达能银行");this.setSize(435,350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置不可改变窗口大小this.setResizable(false);}//布局publicvoidsetLayout(){//用卡片布局Layout=newCardLayout();container=getContentPane();container.setLayout(Layout);//添加第一张卡片panelfirst=newJPanel(null);//设置卡片的背景颜色panelfirst.setBackground(newColor(119,119,253));lbljixu=newJLabel("请放入磁卡,然后继续操作"); //设置卡片在Panel中的位置lbljixu.setBounds(140,90,350,30);//为第一张卡片添加一个Labelpanelfirst.add(lbljixu);//为第一张卡片添加一个按钮btncard=newJButton("继续");btncard.setBounds(310,180,80,30);//为按钮注册事件监听器btncard.addActionListener(this);//开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);//为第一张卡片添加一个按钮btngetcard=newJButton("取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310,220,80,30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);//添加登录输入卡片panelmain=newJPanel(null);panelmain.setBackground(newColor(119,119,253));//添加登录输入卡号JLabellblnumber=newJLabel("请输入您的银行卡卡号:"); panelmain.add(lblnumber);lblnumber.setBounds(30,30,150,30);//设置文本框为密码型txt1=newJTextField(12);//文本框不可选中//txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170,30,200,30);JLabellblpwd=newJLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(30,80,150,30);//设置文本框为密码型txt2=newJPasswordField(12);//文本框不可选中//txt2.enable(false);panelmain.add(txt2);//文本框的输入内容用*显示txt2.setEchoChar('*');txt2.setBounds(170,80,200,30);//添加选择按钮btnsure=newJButton("确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70,160,80,30);//添加重输按钮btn010=newJButton("重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback=newJButton("退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280,160,80,30);//开户btn_addAccount=newJButton("开户");btn_addAccount.setBounds(70,220,80,30);btn_addAccount.addActionListener(this); panelmain.add(btn_addAccount);lblwrong=newJLabel("请注意保护好您的密码!"); panelmain.add(lblwrong);lblwrong.setBounds(180,110,200,30);container.add(panelmain,"main");}//事件处理@SuppressWarnings("deprecation")@OverridepublicvoidactionPerformed(ActionEvente){ DBoperdb=newDBoper();if(e.getSource().equals(btn_addAccount)){ OpenAccountopen=newOpenAccount();open.adduser();}//磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure)){client=db.verifyAccount(Integer.parseInt(txt1.getText()),txt2.getText());if(client!=null){Defaultdefa=newDefault();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText());txt1.setText("");txt2.setText("");}else{lblwrong.setText("卡号或密码不正确,请重新输入!");txt1.setText("");txt2.setText("");}}//重置输入卡号和密码if(e.getSource()==btn010){txt1.setText("");txt2.setText("");lblwrong.setText("请注意保护好您的密码!");}//退出if(e.getSource().equals(btnback)){System.exit(0);}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubDN_ATMATM=newDN_ATM();ATM.setLayout();ATM.setVisible(true);}}GetBalance.java//查询余额packageDN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportAccount.accounts; importDB.DBoper;publicclassGetBalanceextendsJFrameimplementsActionListener{ privateJFramejf;privateContainerc;privateJLabellblremain1,lblremain;privateJButtonbtnremain,btnremain1;accountsaccount=newaccounts();DBoperdb=newDBoper();privateintid=DN_ATM.id;//添加查询余额界面卡片publicvoidgetBalance(){account=db.queryByID(id);jf=newJFrame("FINDDALANCE");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(newColor(119,119,253));lblremain1=newJLabel("尊敬的达能用户您好!");lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain=newJLabel("请点击继续操作查询余额:");lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain=newJButton("继续操作");btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1=newJButton("退出操作");btnremain1.setBounds(200,150,90,30);btnremain1.addActionListener(this);c.add(btnremain1);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@OverridepublicvoidactionPerformed(ActionEvente){//查询余额if(e.getSource()==btnremain){lblremain1.setText("卡号:"+account.getId()+"用户名:"+account.getName());lblremain.setText("您的余额为"+account.getBalance()+"元,是否继续操作");}if(e.getSource()==btnremain1){Defaultdefa=newDefault();defa.defaltDemo();jf.dispose();}publicstaticvoidmain(String[]args){ //TODOAuto-generatedmethodstubGetBalancebalance=newGetBalance();balance.getBalance();}}InMoney.java //存款packageDN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportAccount.accounts;importDB.DBoper; publicclassInMoneyextendsJFrameimplementsActionListener{ privateJLabellblsave,lblsave1;privateJButtonbtnsave,btnsave2;privateJTextFieldtxt2;privatedoublesavemoney;privatedoublelastmoney;privatebooleanflag;privateJFramejf;privateContainerc;accountsaccount=newaccounts();DBoperdb=newDBoper();privateintid=DN_ATM.id;publicvoidInMoney(){account=db.queryByID(id);jf=newJFrame("INMONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);//添加存款显示界面卡片c.setBackground(newColor(119,119,253));lblsave=newJLabel("请在存款口处放入存款");lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1=newJLabel("请注意:只接收100元或100元的整数倍存款");lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2=newJTextField(12);c.add(txt2);txt2.setBounds(95,80,200,30);btnsave=newJButton("放入存款完毕");btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2=newJButton("返回");btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btnsave2);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@OverridepublicvoidactionPerformed(ActionEvente){if(e.getSource()==btnsave){savemoney=Double.parseDouble(txt2.getText());lastmoney=account.getBalance();lastmoney+=savemoney;Stringsql="updateaccountsetbalance="+lastmoney+"whereid="+id;flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this,"存款成功!");txt2.setText("");Defaultdefa=newDefault();defa.defaltDemo();jf.dispose();}else{JOptionPane.showMessageDialog(this,"存款失败!");}}if(e.getSource()==btnsave2){Defaultdefa=newDefault();defa.defaltDemo();jf.dispose();}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubInMoneyinmoney=newInMoney();inmoney.InMoney();}OpenAccount.java//开户packageDN_SYSTEM; importimportimportimportimportimportimportimportimportimportimportimportimportDB.DBoper;importAccount.accounts; publicclassOpenAccountextendsJFrameimplementsActionListener{ privateJFramejf;privateContainerc;privateJTextFieldtxtname,txt_personId;privateJPasswordFieldtxtpwd,txtpwd1;privateJRadioButtonrbt1;privateJRadioButtonrbt2;StringaccountType;//开户,增加新用户publicvoidadduser(){jf=newJFrame("OpenAccount");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);JLabellbname=newJLabel("用户名:");lbname.setBounds(100,40,80,20);txtname=newJTextField();txtname.setBounds(160,40,130,20);c.add(lbname);c.add(txtname);JLabellbpwd=newJLabel("密码:");lbpwd.setBounds(110,65,80,20);txtpwd=newJPasswordField();txtpwd.setBounds(160,65,130,20);txtpwd.setEchoChar('*');c.add(lbpwd);c.add(txtpwd);JLabellbpwd1=newJLabel("确认密码:");lbpwd1.setBounds(86,90,80,20);。

java项目 ATM银行系统 源代码

java项目 ATM银行系统 源代码

//初始密码为123456import java.awt.*;import java。

awt。

event.*;import javax。

swing.*;public class MyATM extends JFrame implements ActionListener{JPanel panelfirst,panelmain,panel3,panel4,panel5,panel6,panel7,panelchangepwd,panelchangepwded,panelsave,panelsaved,panelremain,paneltrans,paneltransed,panelmobile,panelmobiled,panelconsult;JButton btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btnsure,btnback,btnok,btncard,btngetcard,btnincard;JButton btn00,btn01,btn02,btn03,btn04,btn05,btn06,btn07,btn08,btn09,btn010,btnback1,btnremain,btnremain1,btnremain2;JButton btn000,btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn100,btn200,btn300,btn1000,btn500,btnsure1,btnback2,btn0010,btnquok1,btnquok2,btnquok3,btnquok4;JButton btnpwd,btnpwd1,btnpwd2,btnpwd3,btnpwd4,btn11,btn12,btn13,btn14,btn15,btn16,btn17,btn18,btn19,btn20,btnsave,btnsave1,btnsave2,btnsaved,btnsaved1,btnsaved2,btnsaved3;JButton btntra,btntra1,btntra2,btntraed,btntraed1,btn21,btn22,btn23,btn24,btn25,btn26,btn27,btn28,btn29,btn30,btncon,btncon1;JButton btnmo,btnmo1,btnmo2,btnmo30,btnmo50,btnmo100,btnmo200,btnmo500,btnmo10,btnmo11,btnmo12,btnmo13,btnmo14,btnmo15,btnmo16,btnmo17,btnmo18,btnmo19,btnmoed,btnmoed1;JTextField txt2,txttrans,txttrans1,txttrans2,txtmo,txtmo1;JLabel lbljixu,lblpwd,lblwrong,lblqukuan,lblquok1,lblquok2,lblpwd1,lblpwd2,lblpwd3,lblpwd4,lblsave,lblsave1,lblsaved,lblremain,lblremain1,lbltra,lbltra1,lbltra2,lbltraed,lbltraed1;JLabel lblwel,lblwel1,lblmo,lblmo1,lblmo2,lblmo3,lblmoed,lblmoed1,lblcon,lblcon1;JPasswordField txt1,txtpwd,txtpwd1;Container container;CardLayout Layout;int money,savemoney,mobilemoney=0;double lastmoney,trainsmoney;String userpwd,cardnum,trains,username;boolean flag=true,flag1=false,flag2=false,flag3=true,flag4=false,flag5=false;//构造方法public MyATM(){super("罗灿银行”);this。

java项目 ATM银行系统 源代码

java项目 ATM银行系统 源代码

//初始密码为123456import java.awt。

*;import java。

awt。

event。

*;import javax。

swing。

*;public class MyATM extends JFrame implements ActionListener{ JPanel panelfirst,panelmain,panel3,panel4,panel5,panel6,panel7,panelchangepwd,panelchangepwded,panelsave,panelsaved,panelremain,paneltrans,paneltransed,panelmobile,panelmobiled,panelconsult;JButton btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btnsure,btnback,btnok,btncard,btngetcard,btnincard;JButton btn00,btn01,btn02,btn03,btn04,btn05,btn06,btn07,btn08,btn09,btn010,btnback1,btnremain,btnremain1,btnremain2;JButton btn000,btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn100,btn200,btn300,btn1000,btn500,btnsure1,btnback2,btn0010,btnquok1,btnquok2,btnquok3,btnquok4;JButton btnpwd,btnpwd1,btnpwd2,btnpwd3,btnpwd4,btn11,btn12,btn13,btn14,btn15,btn16,btn17,btn18,btn19,btn20,btnsave,btnsave 1,btnsave2,btnsaved,btnsaved1,btnsaved2,btnsaved3;JButton btntra,btntra1,btntra2,btntraed,btntraed1,btn21,btn22,btn23,btn24,btn25,btn26,btn27,btn28,btn29,btn30,btncon,btncon1;JButton btnmo,btnmo1,btnmo2,btnmo30,btnmo50,btnmo100,btnmo200,btnmo500,btnmo10,btnmo11,btnmo12,btnmo13,btnmo14,btnmo15,btnmo16,btnmo17,btnmo18,btnmo19,btnmoed,btnmoed1;JTextField txt2,txttrans,txttrans1,txttrans2,txtmo,txtmo1;JLabel lbljixu,lblpwd,lblwrong,lblqukuan,lblquok1,lblquok2,lblpwd1,lblpwd2,lblpwd3,lblpwd4,lblsave,lblsave1,lblsaved,lblremain,lblremain1,lbltra,lbltra1,lbltra2,lbltraed,lbltraed1;JLabel lblwel,lblwel1,lblmo,lblmo1,lblmo2,lblmo3,lblmoed,lblmoed1,lblcon,lblcon1;JPasswordField txt1,txtpwd,txtpwd1;Container container;CardLayout Layout;int money,savemoney,mobilemoney=0;double lastmoney,trainsmoney;String userpwd,cardnum,trains,username;boolean flag=true,flag1=false,flag2=false,flag3=true,flag4=false,flag5=false;//构造方法public MyATM(){super("罗灿银行”);this。

java实现银行管理系统

java实现银行管理系统

java实现银⾏管理系统本⽂实例为⼤家分享了java实现银⾏管理系统的具体代码,供⼤家参考,具体内容如下Bank类package First;import java.util.TreeSet;//银⾏类public class Bank {private String Bankname = "坑对对银⾏"; //银⾏名称TreeSet<User> holder = null; //银⾏存储的信息private static Bank INSTANCE = new Bank();private Bank() {} //私有化银⾏类public static Bank getInstance() {// TODO Auto-generated method stubreturn INSTANCE;}//存款功能public void saveMoney(User user,double money) {//初始⾦额与存⼊⾦额相加double sum = user.getSum()+money;user.setSum(sum);System.out.print(money+"存款成功"+",当前余额是:"+user.getSum());System.out.print("\n");}//取款功能public void drawMoney(User user,double money,String pw) {if(user.getPw().equals(pw)) { //先判断取款密码if(user.getSum()>=money) { //判断余额user.setSum(user.getSum()-money);System.out.print("取款成功");System.out.print("\n");System.out.print("当前余额为:"+"\t"+user.getSum());System.out.print("\n");}else {System.out.print("抱歉余额不⾜当前余额:"+user.getSum());System.out.print("\n");}}}//查看余额以及信息public void looksum(User user) {System.out.print("姓名:"+user.getName()+",账号:"+user.getAccount()+",余额:"+user.getSum());System.out.print("\n");}//欢迎语句public void welcom(User user) {if(user.getSexual().equals("男")) {System.out.print(user.getName()+" 先⽣!!"+" "+(this.Bankname)+" 欢迎您");System.out.print("\n");}else if(user.getSexual().equals("⼥")){System.out.print(user.getName()+" ⼥⼠!!"+" "+(this.Bankname)+" 欢迎您");System.out.print("\n");}}//再见语句public void GoodBye(User user) {if(user.getSexual().equals("男")) {System.out.print(user.getName()+" 先⽣!!"+" "+(this.Bankname)+" 祝您⽣活愉快");System.out.print("\n");}else if(user.getSexual().equals("⼥")){System.out.print(user.getName()+" ⼥⼠!!"+" "+(this.Bankname)+" 祝您⽣活愉快");System.out.print("\n");}}}Data:数据存储类package First;import java.util.TreeSet;//模拟⼀个数据库//银⾏的数据库public class Data {TreeSet<User> holder = new TreeSet<User>(new MyComparator()); //⽤于存储⽤户信息的容器---⾃定义⽐较规则 File file = File.getFile(); //获取⼀个⽂件类private static Data data = new Data();//单例模式--因为存储数据的类唯⼀.所以不能随意被实例化private Data() {} //私有化构造⽅法public static Data getData() { //提供返回该对象的静态⽅法return data;}//添加⽤户public void addUser(User user) {holder.add(user);System.out.print("注册成功!!");System.out.print("\n");}//删除⽤户public void removeUser(User user) {if(holder.contains(user)) { //如果容器中包含所user对象,则移除对象holder.remove(user);}else { //如果不包含则打印语句System.out.print("抱歉请检查输⼊的信息是否正确");System.out.print("\n");}}//获取容器public TreeSet<User> getHolder() {return holder;}//写⼊容器public void setHolder(TreeSet<User> holder) {this.holder = holder;}}FIie:⽂件IO类package First;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.util.Iterator;import java.util.TreeSet;/** ⽂件类--负责向内存中初始化信息以及程序结束后向内存中存⼊信息* */public class File {TreeSet<User> holder = Data.getData().getHolder(); //从Data数据库中获取容器//⽂件类只供使⽤不能被任意实际化public static File FILE; //私有化⼀个File类private File() {};public static File getFile() { //对外界提供获取⽅法return FILE;}//保存到⽂件⾥public static void SaveToFile(TreeSet<User> list) { //将获取到的容器存⼊到⽂件中----序列化ObjectOutputStream oo = null;try {oo = new ObjectOutputStream(new FileOutputStream(".\\src\\Test\\text1.txt")); //获取⽂件存储地址oo.writeObject(list); //将容器写⼊} catch (Exception ex) {ex.printStackTrace();}finally {try {oo.close(); //将流关闭}catch(IOException e) {e.printStackTrace();}}}//从⽂件⾥读取public static TreeSet<User> ReadFromFile() {ObjectInputStream ois = null;TreeSet<User> list = null;try {ois = new ObjectInputStream(new FileInputStream(".\\src\\Test\\text1.txt"));//反序列化从⽂件中获取容器加载到内存list = Data.getData().getHolder(); //获取容器list = (TreeSet<User>) ois.readObject(); //从流中获取对象Iterator it = list.iterator(); //迭代器System.out.print("当前⽤户信息:");System.out.print("\n");System.out.print("\n");while(it.hasNext()) { //迭代初始信息User user = (User) it.next();System.out.print("\t"+"姓名:"+user.getName()+"\t"+"账号:"+user.getAccount()+"\t"+"密码:"+user.getPassword()+"\t"+"余额:"+user.getSum()+"\t"); System.out.print("\n");System.out.print("\n");}} catch (Exception ex) {ex.printStackTrace();}finally {try {ois.close(); //将流关闭}catch(IOException e){e.printStackTrace();}}return list;}}MyComparator:⾃定义⽐较器类package First;import java.io.Serializable;import parator;//⾃定义⽐较器//想要存⼊集合必须实现序列化和反序列化public class MyComparator implements Comparator,Serializable{/****/private static final long serialVersionUID = 1L;@Overridepublic int compare(Object arg0, Object arg1) {User user1 = (User)arg0; //重写⽐较⽅法 --- 强转成User类型User user2 = (User)arg1;return user1.getAccount().compareTo(user2.getAccount());//⽐较两个银⾏账户}}Operate:系统核⼼package First;import java.util.Iterator;import java.util.Scanner;import java.util.TreeSet;//后台操作系统//后台管理员public class Operate {Scanner sc = new Scanner(System.in); //键盘录⼊TreeSet<User> holder = Data.getData().getHolder(); //从Data数据库中获取容器Bank bank = Bank.getInstance(); //获取⼀个银⾏类File file = File.getFile(); //获取⼀个⽂件类//登录菜单public void registerMenu(){System.out.print("****************************");System.out.print("\n");System.out.print("\n");System.out.print(" 欢迎来到坑多多银⾏登录系统\n");System.out.print("\n");System.out.print("****************************");System.out.print("\n");System.out.print("\n");holder = File.ReadFromFile(); //从⽂件中获取容器Data.getData().setHolder(holder); //把从⽂件中获取容器存储到数据库中int str=1; //从键盘获取数字while(str!=0) {System.out.print("****************************");System.out.print("\n");System.out.print(" 1: 登录 ");System.out.print("\n");System.out.print(" 2: 注册 ");System.out.print("\n");System.out.print(" 3: 忘记密码");System.out.print("\n");System.out.print(" 4: 注销⽤户");System.out.print("\n");System.out.print(" 0: 退出");System.out.print("\n");System.out.print("****************************");System.out.print("\n");System.out.print("请输⼊:");str = sc.nextInt();switch(str){ //根据⽤户输⼊的值进⾏选择case 1:System.out.print("请输⼊您的账号:");String account = sc.next(); //从键盘中获取录⼊⽤户名System.out.print("请输⼊您的密码:");String pw = sc.next(); //从键盘中录⼊密码User user = logon(holder,account,pw);if(user!=null) { //判断是否登录成功System.out.print("登录成功欢迎使⽤");System.out.print("\n");System.out.print("正在跳转到银⾏操作界⾯.........");System.out.print("\n");this.BankMenu(user); //如果登录成功则将user对象传⼊到银⾏操作界⾯并跳转 }else {System.out.print("登录失败请从新输⼊"); //如果登录失败打印此语句System.out.print("\n");}break;case 2:this.logon(); //调⽤注册⽅法break;case 3:this.modify(); //调⽤修改⽅法break;case 4:holder = logout(holder); //调⽤删除操作break;case 0:File.SaveToFile(holder); //退出系统式将信息保存到⽂件中System.out.print("再见");System.out.print("\n");default:System.out.print("输⼊错误");System.out.print("\n");}}}//登录⽅法public User logon(TreeSet<User> holder,String account,String pw) {Iterator<User> it = holder.iterator(); //获取迭代器while(it.hasNext()) {User user = it.next();if(user.getAccount().equals(account)&&user.getPassword().equals(pw)){System.out.print("登录成功!!");System.out.print("\n");return user;}}System.out.print("账户或密码错误登录失败!!");System.out.print("\n");return null;}//注册⽅法体public void logon(){System.out.print("欢迎来到注册界⾯");System.out.print("\n");String name; //⽤户名String account; //银⾏账号String password; //密码String pw; //取款密码double sum; //账户⾦额String sexual; //性别User user = new User(); //先创建⼀个空参的user对象boolean flag = true; //语句的开关while(flag) { //将注册的信息依次输⼊switch(1) {case 1:System.out.print("请输⼊姓名:"); //依次从键盘中获取对应的姓名----正则表达式 name = sc.next();user.setName(name); //将名字写⼊对象中case 2:System.out.print("请输⼊账号(9位数字):");account = sc.next(); //从键盘中获取账号String reges ="[0-9]{9}"; //正则表达式规则对账号进⾏限制if(!account.matches(reges)) { //如果不符合要求则报错System.out.print("账号不符合规范!!");System.out.print("\n");System.out.print("请重新注册");System.out.print("\n");break;}user.setAccount(account); //将账号写⼊对象中case 3:System.out.print("请输⼊密码(6位):");password = sc.next();reges ="[0-9]{6}"; //正则表达式规则if(!password.matches(reges)){ //如果密码不符合正则规则则报错System.out.print("密码不符合规范!!");System.out.print("\n");System.out.print("请重新注册");System.out.print("\n");break;}user.setPassword(password); //将密码写⼊对象中case 4:System.out.print("请输⼊取款密码(6位):");pw = sc.next();reges ="[0-9]{6}"; //正则表达式规则if(!pw.matches(reges)) {System.out.print("取款密码不符合规范!!");System.out.print("\n");System.out.print("请重新注册");System.out.print("\n");break;}user.setPw(pw); //将取款密码写⼊到对象中case 5:System.out.print("请输⼊⾦额:");sum = sc.nextDouble();user.setSum(sum); //将⾦额写⼊到对象中case 6:System.out.print("请输⼊性别:");sexual = sc.next();user.setSexual(sexual); //将性别写⼊到对象中case 7:if(!holder.contains(user)){Data.getData().addUser(user); //⼀切准确⽆误后将user存⼊数据库Data中 }else {System.out.print("⽤户存在");System.out.print("\n");//结束循环}flag = false;break;}}}//忘记密码操作public void modify() {boolean flag = true;Iterator<User> it = holder.iterator(); //获取迭代器System.out.print("请输⼊账户:");String account = sc.next(); //从键盘中获取账户while(it.hasNext()) {User user = it.next();if(user.getAccount().equals(account)){ //如果容器中有这个对象则对它进⾏修改 System.out.print("请输⼊新账户的密码:");String pw = sc.next(); //从监盘上录⼊新的密码String reges ="[0-9]{6}"; //正则表达式规则if(!pw.matches(reges)) { //如果密码不符合正则规则则报错System.out.print("密码不符合规范!!");System.out.print("\n");}else { //正则表达式判断是否符合条件holder.remove(user); //先从原容器中删除useruser.setPassword(pw); //修改user的属性holder.add(user); //然后再向容器中添加System.out.print("修改成功");System.out.print("\n");flag = false;break;}}}if(flag) {System.out.print("没有找到该⽤户");System.out.print("\n");}}//注销⽅法public TreeSet<User> logout(TreeSet<User> list) {String username; //⽤户名String password; //密码System.out.print("请输⼊⽤户账号:");username = sc.next(); //从键盘录⼊⽤户名System.out.print("请输⼊密码:");password = sc.next(); //从键盘录⼊密码Iterator it = list.iterator(); //获取迭代器while(it.hasNext()) {User user = (User)it.next(); //获取对象if(user.getAccount().equals(username)&&user.getPassword().equals(password)){ list.remove(user); //如果录⼊的信息匹配则从容器中删除user对象System.out.print("注销成功!!");System.out.print("\n");return list;}}System.out.print("账号或者密码错误"); //不匹配打印提⽰语句System.out.print("\n");return list;}//银⾏操作界⾯public void BankMenu(User user) {bank.welcom(user); //银⾏调⽤欢迎语句System.out.print("****************************");System.out.print("\n");System.out.print("\n");System.out.print(" 欢迎来到坑多多银⾏擦操作系统\n");System.out.print("\n");int str = 1;while(str!=0) {System.out.print("****************************");System.out.print("\n");System.out.print(" 1: 取钱 ");System.out.print("\n");System.out.print(" 2: 存钱 ");System.out.print("\n");System.out.print(" 3: 查看余额");System.out.print("\n");System.out.print(" 0: 退出登录");System.out.print("\n");System.out.print("****************************");System.out.print("\n");System.out.print("\n");System.out.print("请输⼊您的选项:"); //从键盘中读取字符串str = sc.nextInt();switch(str){ //根据⽤户输⼊的值进⾏选择case 1: //取钱选项System.out.print("请输⼊取款密码:");String pw = sc.next(); //从键盘获取输⼊的密码if(user.getPw().equals(pw)) { //将输⼊的取款密码与⽤户的密码进⾏⽐对:如果相同则继续执⾏ System.out.print("请输⼊取款⾦额:");double money = sc.nextDouble(); //从键盘获取输⼊的⾦额if(money>=0) { //判断⾦额是否有误bank.drawMoney(user, money, pw); //调⽤取款⽅法}else {System.out.print("输⼊⾦额错误");System.out.print("\n");}}else {System.out.print("输⼊密码有误");System.out.print("\n");}break;case 2:System.out.print("请输⼊取款⾦额:");System.out.print("\n");double money1 = sc.nextDouble(); //从键盘获取输⼊的⾦额if(money1>=0) { //判断⾦额是否有误bank.saveMoney(user, money1);; //调⽤存款⽅法}else {System.out.print("输⼊⾦额错误");System.out.print("\n");}break;case 3:bank.looksum(user); //调⽤银⾏---查询账户操作break;case 0:bank.GoodBye(user); //调⽤结束语句break;default:System.out.print("输⼊错误");System.out.print("\n");}}}}User类:package First;import java.io.Serializable;/** 这是⼀个User类* */public class User implements Serializable{/*** 实现接⼝,⽤于序列化和反序列化*/private static final long serialVersionUID = 1L;private String name; //⽤户名private String account; //银⾏账号private String password; //密码private String pw; //取款密码private double sum; //账户⾦额private String sexual; //性别//获取⽤户名public String getName() {return name;}//写⼊⽤户名public void setName(String name) {}//获取账号public String getAccount() {return account;}//写⼊账号public void setAccount(String account) {this.account = account;}//获取密码public String getPassword() {return password;}//修改密码public void setPassword(String password) {this.password = password;}//查看余额public double getSum() {return sum;}//修改余额public void setSum(double sum) {this.sum = sum;}//写⼊性别public String getSexual() {return sexual;}//修改性别public void setSexual(String sexual) {this.sexual = sexual;}//获取取款密码public String getPw() {return pw;}//写⼊取款密码public void setPw(String pw) {this.pw = pw;}//hashCode⽐较⽅法@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((account == null) ? 0 : account.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());result = prime * result + ((password == null) ? 0 : password.hashCode()); result = prime * result + ((pw == null) ? 0 : pw.hashCode());result = prime * result + ((sexual == null) ? 0 : sexual.hashCode());long temp;temp = Double.doubleToLongBits(sum);result = prime * result + (int) (temp ^ (temp >>> 32));return result;}//equals⽐较⽅法/** 知识点:* public boolean equals(Object obj)名称不可改变* */@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;User other = (User) obj;if (account == null) {if (other.account != null)return false;} else if (!account.equals(other.account))return false;if ( != null)return false;} else if (!name.equals())return false;if (password == null) {if (other.password != null)return false;} else if (!password.equals(other.password))return false;if (pw == null) {if (other.pw != null)return false;} else if (!pw.equals(other.pw))return false;if (sexual == null) {if (other.sexual != null)return false;} else if (!sexual.equals(other.sexual))return false;if (Double.doubleToLongBits(sum) != Double.doubleToLongBits(other.sum))return false;return true;}//初始化⽤户User(String name,String account,String password,String pw,double sum,String sexual){ = name;this.account = account;this.password = password;this.sum = sum;this.sexual = sexual;this.pw = pw;}//空参构造函数User(){}}Main()类package First;public class Test {//测试类----唯⼀的主函数public static void main(String[] args) {Operate operate = new Operate();operate.registerMenu(); //调⽤登录⽅法}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

J a v a小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts {protected int id;//银行账号protected String password;//用户密码protected String name;//用户型号protected String personId;//身份账号protected int accountType;//账号类型,0代表储蓄卡,1代表信用卡protected double balance;//账户余额。

之所以定义为protected是让他的子类可以直接用,不需要通过方法来赋值。

protected double ceiling;public String getPassword(){return password;}public void setPassword(String password){this.password=password;}public String getName(){return name;}public void setName(String name){=name;}public String getPersonId(){return personId;}public void setPersonId(String personId){this.personId=personId;}public int getAccountType(){return accountType;}public void setAccountType(int accountType){this.accountType=accountType;}public double getBalance(){return balance;}public void setBalance(double balance){this.balance=balance;}public int getId(){return id;}public void setId(int id){this.id=id;}public double getCeiling(){return ceiling;}public void setCeiling(double ceiling){this.ceiling=ceiling;}//无参数构造方法public accounts(){}//构造方法public accounts(String password,String name,String personId,int accountType, double balance,double ceiling){super();this.password=password;=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;}//存款public void deposit(double money){balance+=money;}//取款public void withdraw(double money){if(accountType==1){if((balance+ceiling)<money){对不起,已超出您的信用额度!");}else{balance-=money;}}else{if(balance<money){对不起,账户余额不足!");}else{balance-=money;}}}}DBoper.javapackage DB;import java.sql.*;importimport Account.accounts;public class DBoper {private Connection conn = null;private Statement st = null;private PreparedStatement pstmt = null;private ResultSet rs = null;private ArrayList<accounts> result;//连接数据库public Connection getConnection(){try{Class.forName(conn=}catch(Exception e){数据库连接失败");}return conn;}//修改删除用户数据public boolean accountDataUpdate(String sql){ conn=getConnection();try{pstmt=conn.prepareStatement(sql);pstmt.executeUpdate();数据更新成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();更新失败");return false;}}//依据id来修改记录public boolean dataupdateid(accounts user, int id) {conn = getConnection();try {String sql = "update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=? where id="+ id;pstmt = conn.prepareStatement(sql);pstmt.setString(1, user.getName());pstmt.setString(2, user.getPassword());pstmt.setString(3, user.getPersonId());pstmt.setInt(4, user.getAccountType());pstmt.setDouble(5, user.getBalance());pstmt.setDouble(6, user.getCeiling());pstmt.executeUpdate();操作成功");return true;}catch (SQLException e) {e.printStackTrace();操作失败");return false;}}//插入用户数据public boolean accountDataInsert(accounts account){conn=getConnection();try{pstmt=conn.prepareStatement("insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?)");pstmt.setString(1, account.getName());pstmt.setString(2, account.getPassword());pstmt.setString(3, account.getPersonId());pstmt.setInt(4, account.getAccountType());pstmt.setDouble(5, account.getBalance());pstmt.setDouble(6, account.getCeiling());pstmt.executeUpdate();新用户数据插入成功");conn.close();return true;}catch(SQLException e){e.printStackTrace();插入失败");return false;}}//查询数据public ResultSet dataquery(String sql) {conn = getConnection();try {pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();}catch (SQLException e) {e.printStackTrace();检索失败");}return rs;}public ResultSet testlist() {try {String sql = "select * from account where id =1001";pstmt = conn.prepareStatement(sql);sql);rs = pstmt.executeQuery();} catch (SQLException e) {e.printStackTrace();检索失败");}return rs;}public ArrayList<accounts> testt(int id) {ArrayList<accounts> list = new ArrayList<accounts>();conn = getConnection();try {String sql = "select * from account where id=" + id;pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next()) {accounts user = new accounts();user.setName(rs.getString("username"));user.setPassword(rs.getString("userpwd"));user.setPersonId(rs.getString("personId"));user.setAccountType(rs.getInt("accountType"));user.setBalance(rs.getDouble("balance"));user.setCeiling(rs.getDouble("ceiling"));list.add(user);}}catch (SQLException e) {e.printStackTrace();检索失败");}return list;}//根据卡号和密码验证用户是否存在public boolean verify(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();if(rs.next()){return true;}else{return false;}}catch(SQLException e){e.printStackTrace();return false;}}/*** 登录验证*/public accounts verifyAccount(int id, String password) {boolean flag = verify(id, password);if(flag){accounts account=queryByIDandPassword(id, password);return account;}else{用户不存在!");return null;}}//根据卡号和密码查询信息public accounts queryByIDandPassword(int id,String password){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=? and userpwd=?");pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}//根据卡号查询信息public accounts queryByID(int id){conn=getConnection();try{pstmt=conn.prepareStatement("select * from account where id=?");pstmt.setInt(1, id);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()){account.setId(rs.getInt("id"));account.setName(rs.getString("username"));account.setPassword(rs.getString("userpwd"));account.setPersonId(rs.getString("personId"));account.setAccountType(rs.getInt("accountType"));account.setBalance(rs.getDouble("balance"));account.setCeiling(rs.getDouble("ceiling"));}return account;}catch(SQLException e){e.printStackTrace();return null;}}public static void main(String[] args) {// TODO Auto-generated method stubDBoper op=new DBoper();ArrayList<accounts> list=op.testt(1001);for(int i=0;i<list.size();i++){accounts user=new accounts();user=list.get(i);user.getName());user.getPassword());user.getPersonId());user.getAccountType());user.getBalance());user.getCeiling());}}}//图像界面文件夹DN_SYSTEMDefault.java //主界面package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionListener{ accounts account=DN_ATM.client;DBoper db=new DBoper();private JFrame jf;private JButton btn0,btn1,btn2,btn3,btn4,btn5;private Container c;public void defaltDemo() {//添加主界面卡片//DN_ATM.id;int id=DN_ATM.id;//account=db.queryByID(id);jf=new JFrame("DEFAULT");c=jf.getContentPane();c.setLayout(null);c.setBackground(new Color(119,119,253));JLabel lblwel = new JLabel("欢迎"+account.getName()+"用达能银行ATM系统");lblwel.setBounds(20, 15, 350, 30);c.add(lblwel);JLabel lblwel1 = new JLabel("请选择您需要的交易类型");lblwel1.setBounds(120, 45, 350, 30);c.add(lblwel1);btn1 = new JButton("取款服务");btn1.addActionListener(this);btn1.setBounds(70, 90, 100, 30);c.add(btn1);btn2=new JButton("存款服务");btn2.addActionListener(this);btn2.setBounds(210, 90, 100, 30);c.add(btn2);btn3 = new JButton("查询余额");btn3.addActionListener(this);btn3.setBounds(70, 150, 100, 30);c.add(btn3);btn4 = new JButton("转账服务");btn4.addActionListener(this);btn4.setBounds(210, 150, 100, 30);c.add(btn4);btn5 = new JButton("注销账户");btn5.addActionListener(this);btn5.setBounds(70, 210, 100, 30);c.add(btn5);btn0 = new JButton("退出操作");btn0.addActionListener(this);btn0.setBounds(210, 210, 100, 30);c.add(btn0);jf.setVisible(true);jf.setResizable(false);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}//事件处理@Overridepublic void actionPerformed(ActionEvent e){//取款服务if(e.getSource().equals(btn1)){OutMoney outmoney=new OutMoney();outmoney.outMoney();jf.dispose();}//存款服务if(e.getSource().equals(btn2)){InMoney inmoney=new InMoney();inmoney.InMoney();jf.dispose();}//查询余额if(e.getSource().equals(btn3)){GetBalance getbalance=new GetBalance();getbalance.getBalance();jf.dispose();}//转账服务if(e.getSource().equals(btn4)){TransferAccounts tranfer=new TransferAccounts();tranfer.transferAccounts();jf.dispose();}//注销账户if(e.getSource().equals(btn5)){String sql="delete from account where id="+account.getId();boolean flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this,"注销成功!");}else{JOptionPane.showMessageDialog(this, "注销失败!");}}if(e.getSource().equals(btn0)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDefault defaults=new Default();defaults.defaltDemo();}}DN_ATM.java//功能界面package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimportimportimport DB.DBoper;import Account.accounts;public class DN_ATM extends JFrame implements ActionListener{ private JLabel lbljixu;private JButton btngetcard;private JButton btncard,btn010,btn_addAccount,btnsure,btnback;private JTextField txt1;private JPasswordField txt2;private Container container;private CardLayout Layout;private JLabel lblwrong;private JPanel panelfirst,panelmain;public static int id;static accounts client = null;public DN_ATM(){super("达能银行");this.setSize(435, 350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置不可改变窗口大小this.setResizable(false);}//布局public void setLayout(){//用卡片布局Layout = new CardLayout();container = getContentPane();container.setLayout(Layout);//添加第一张卡片panelfirst = new JPanel(null);//设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253));lbljixu = new JLabel("请放入磁卡,然后继续操作");//设置卡片在Panel中的位置lbljixu.setBounds(140, 90, 350, 30);//为第一张卡片添加一个Labelpanelfirst.add(lbljixu);//为第一张卡片添加一个按钮btncard = new JButton("继续");btncard.setBounds(310, 180, 80, 30);//为按钮注册事件监听器btncard.addActionListener(this);//开始时设置按钮不可按btncard.setEnabled(false);panelfirst.add(btncard);//为第一张卡片添加一个按钮btngetcard = new JButton("取卡");btngetcard.setEnabled(false);btngetcard.setBounds(310, 220, 80, 30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);//添加登录输入卡片panelmain = new JPanel(null);panelmain.setBackground(new Color(119,119,253));//添加登录输入卡号JLabel lblnumber = new JLabel("请输入您的银行卡卡号:"); panelmain.add(lblnumber);lblnumber.setBounds(30, 30, 150, 30);//设置文本框为密码型txt1 = new JTextField(12);//文本框不可选中//txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170, 30, 200, 30);JLabel lblpwd = new JLabel("请输入您的银行卡密码:"); panelmain.add(lblpwd);lblpwd.setBounds(30, 80, 150, 30);//设置文本框为密码型txt2 = new JPasswordField(12);//文本框不可选中//txt2.enable(false);panelmain.add(txt2);//文本框的输入内容用*显示txt2.setEchoChar('*');txt2.setBounds(170, 80, 200, 30);//添加选择按钮btnsure = new JButton("确定");btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70, 160, 80, 30);//添加重输按钮btn010 = new JButton("重输");btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback = new JButton("退出");btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280, 160, 80, 30);//开户btn_addAccount = new JButton("开户");btn_addAccount.setBounds(70, 220, 80, 30);btn_addAccount.addActionListener(this);panelmain.add(btn_addAccount);lblwrong = new JLabel("请注意保护好您的密码!");panelmain.add(lblwrong);lblwrong.setBounds(180, 110, 200, 30);container.add(panelmain, "main");}//事件处理@SuppressWarnings("deprecation")@Overridepublic void actionPerformed(ActionEvent e){DBoper db=new DBoper();if(e.getSource().equals(btn_addAccount)){OpenAccount open=new OpenAccount();open.adduser();}//磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure)){client = db.verifyAccount(Integer.parseInt(txt1.getText()), txt2.getText());if(client!=null){Default defa=new Default();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText());txt1.setText("");txt2.setText("");}else{lblwrong.setText("卡号或密码不正确,请重新输入!");txt1.setText("");txt2.setText("");}}//重置输入卡号和密码if(e.getSource()==btn010){txt1.setText("");txt2.setText("");lblwrong.setText("请注意保护好您的密码!");}//退出if(e.getSource().equals(btnback)){System.exit(0);}}public static void main(String[] args) {// TODO Auto-generated method stubDN_ATM ATM=new DN_ATM();ATM.setLayout();ATM.setVisible(true);}}GetBalance.java //查询余额package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class GetBalance extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JLabel lblremain1,lblremain;private JButton btnremain,btnremain1;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;//添加查询余额界面卡片public void getBalance(){account=db.queryByID(id);jf=new JFrame("FIND DALANCE");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(new Color(119,119,253));lblremain1 = new JLabel("尊敬的达能用户您好!");lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain = new JLabel("请点击继续操作查询余额:");lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain = new JButton("继续操作");btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1 = new JButton("退出操作");btnremain1.setBounds(200,150,90,30);btnremain1.addActionListener(this);c.add(btnremain1);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){//查询余额if(e.getSource()==btnremain){lblremain1.setText("卡号:"+account.getId()+" 用户名:"+account.getName());lblremain.setText("您的余额为"+account.getBalance()+"元,是否继续操作?");}if(e.getSource()==btnremain1){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubGetBalance balance=new GetBalance();balance.getBalance();}}InMoney.java//存款package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;public class InMoney extends JFrame implements ActionListener{private JLabel lblsave,lblsave1;private JButton btnsave,btnsave2;private JTextField txt2;private double savemoney ;private double lastmoney;private boolean flag;private JFrame jf;private Container c;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void InMoney(){account=db.queryByID(id);jf=new JFrame("IN MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);//添加存款显示界面卡片c.setBackground(new Color(119,119,253));lblsave = new JLabel("请在存款口处放入存款");lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1 = new JLabel("请注意:只接收100元或100元的整数倍存款");lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2 = new JTextField(12);c.add(txt2);txt2.setBounds(95, 80, 200, 30);btnsave = new JButton("放入存款完毕");btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2 = new JButton("返回");btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btnsave2);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);}@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btnsave){savemoney=Double.parseDouble(txt2.getText());lastmoney=account.getBalance();lastmoney+=savemoney;String sql = "update account set balance="+lastmoney+"where id="+ id;flag=db.accountDataUpdate(sql);if(flag){JOptionPane.showMessageDialog(this, "存款成功!");txt2.setText("");Default defa=new Default();defa.defaltDemo();jf.dispose();}else{JOptionPane.showMessageDialog(this, "存款失败!");}}if(e.getSource()==btnsave2){Default defa=new Default();defa.defaltDemo();jf.dispose();}}public static void main(String[] args) {// TODO Auto-generated method stubInMoney inmoney=new InMoney();inmoney.InMoney();}}OpenAccount.java //开户package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimportimportimportimport DB.DBoper;import Account.accounts;public class OpenAccount extends JFrame implements ActionListener{ private JFrame jf;private Container c;private JTextField txtname,txt_personId;private JPasswordField txtpwd,txtpwd1;private JRadioButton rbt1;private JRadioButton rbt2;String accountType;//开户,增加新用户public void adduser(){jf=new JFrame("Open Account");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);JLabel lbname=new JLabel("用户名:");lbname.setBounds(100, 40, 80, 20);txtname=new JTextField();txtname.setBounds(160, 40, 130, 20);c.add(lbname);c.add(txtname);JLabel lbpwd=new JLabel("密码:");lbpwd.setBounds(110, 65, 80, 20);txtpwd=new JPasswordField();txtpwd.setBounds(160, 65, 130, 20);txtpwd.setEchoChar('*');c.add(lbpwd);c.add(txtpwd);JLabel lbpwd1=new JLabel("确认密码:");lbpwd1.setBounds(86, 90, 80, 20);txtpwd1 = new JPasswordField();txtpwd1.setBounds(160, 90, 130, 20);txtpwd1.setEchoChar('*');c.add(lbpwd1);c.add(txtpwd1);JLabel lbpersonId=new JLabel("身份证号:");lbpersonId.setBounds(86, 115, 80, 20);txt_personId = new JTextField();txt_personId.setBounds(160, 115, 130, 20);c.add(lbpersonId);c.add(txt_personId);JLabel lbtype=new JLabel("账户类型:");lbtype.setBounds(86, 120, 80, 60);rbt1=new JRadioButton("信用卡");rbt1.setBounds(160, 135, 70, 30);rbt2=new JRadioButton("储蓄卡");rbt2.setBounds(225, 135, 70, 30);ButtonGroup group=new ButtonGroup();group.add(rbt2);group.add(rbt1);c.add(lbtype);c.add(rbt2);c.add(rbt1);JButton btnsubmit=new JButton("提交");btnsubmit.setBounds(100, 190, 80, 20);JButton btnreset=new JButton("重置");btnreset.setBounds(205, 190, 80, 20);c.add(btnsubmit);c.add(btnreset);btnsubmit.addActionListener(this);btnreset.addActionListener(this);jf.setVisible(true);jf.setSize(400,300);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }public static void main(String[] args) {// TODO Auto-generated method stubOpenAccount openA=new OpenAccount();openA.adduser();}@Overridepublic void actionPerformed(ActionEvent e){accounts account=new accounts();account.setName(txtname.getText());if(txtpwd.getText().equals(txtpwd1.getText())){account.setPassword(txtpwd.getText());}else{JOptionPane.showMessageDialog(this,"两次输入的密码不一致,请重新输入!");}account.setPersonId(txt_personId.getText());if(rbt1.isSelected())accountType="1";if(rbt2.isSelected())accountType="0";account.setAccountType(Integer.parseInt(accountType));account.setBalance(0);if(accountType.equals("1")){account.setCeiling(5000.0);}else{account.setCeiling(0);}DBoper db=new DBoper();if(db.accountDataInsert(account)){JOptionPane.showMessageDialog(this,"开户成功!");jf.dispose();//关闭当前登录窗体return;}else{JOptionPane.showMessageDialog(this,"开户失败!");return;}}}OutMoney.java//取款package DN_SYSTEM;importimportimportimportimportimportimportimportimportimportimport Account.accounts;import DB.DBoper;importimportpublic class OutMoney extends JFrame implements ActionListener{private JFrame jf;private JButton btn100,btn200,btn300,btn500,btn1000;private JButton btn001,btn002,btn003,btn004,btn005,btn006,btn007,btn008,btn009,btn000;private JButton btnsure1,btn0010,btnback2;private JTextField txt2;private Container c;private JLabel lblqukuan;private int money;private double lastmoney;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void outMoney(){account=db.queryByID(id);jf=new JFrame("OUT MONEY");c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);//添加取款页面卡片//panel4=new JPanel(null);c.setBackground(new Color(119,119,253));lblqukuan = new JLabel("请输入您的取款金额:");c.add(lblqukuan);lblqukuan.setBounds(115, 20, 150, 30);lblqukuan=new JLabel("提示:只能是100元或100元的整数倍");c.add(lblqukuan);lblqukuan.setBounds(115, 50, 300, 30);txt2 = new JTextField(12);txt2.enable(false);c.add(txt2);txt2.setBounds(115, 90, 200, 30);btn100 = new JButton("100");c.add(btn100);btn200 = new JButton("200");c.add(btn200);btn200.addActionListener(this);btn200.setBounds(115, 190, 60, 30); btn300 = new JButton("300");c.add(btn300);btn300.addActionListener(this);btn300.setBounds(185, 190, 60, 30); btn500 = new JButton("500");btn500=new JButton("500");c.add(btn500);btn500.addActionListener(this);btn500.setBounds(255, 190, 60, 30); btn1000 = new JButton("1000");c.add(btn1000);btn1000.addActionListener(this);btn1000.setBounds(325, 190, 65, 30); btn001 = new JButton("1");c.add(btn001);btn001.addActionListener(this);btn001.setBounds(45, 230, 60, 30); btn002 = new JButton("2");c.add(btn002);btn002.addActionListener(this);btn002.setBounds(115, 230, 60, 30); btn003 = new JButton("3");c.add(btn003);btn003.addActionListener(this);btn003.setBounds(185, 230, 60, 30); btn004 = new JButton("4");c.add(btn004);btn004.addActionListener(this);btn004.setBounds(255, 230, 60, 30); btn005 = new JButton("5");c.add(btn005);btn005.addActionListener(this);btn005.setBounds(325, 230, 65, 30); btn006 = new JButton("6");c.add(btn006);btn006.addActionListener(this);btn006.setBounds(45, 270, 60, 30); btn007 = new JButton("7");c.add(btn007);btn008 = new JButton("8");c.add(btn008);btn008.addActionListener(this);btn008.setBounds(185, 270, 60, 30);btn009 = new JButton("9");c.add(btn009);btn009.addActionListener(this);btn009.setBounds(255, 270, 60, 30);btn000 = new JButton("0");c.add(btn000);btn000.addActionListener(this);btn000.setBounds(325, 270, 65, 30);btnsure1 = new JButton("确定");c.add(btnsure1);btnsure1.addActionListener(this);btnsure1.setBounds(70, 140, 80, 30);btn0010 = new JButton("重输");c.add(btn0010);btn0010.addActionListener(this);btn0010.setBounds(175, 140, 80, 30);btnback2 = new JButton("返回");c.add(btnback2);btnback2.addActionListener(this);btnback2.setBounds(280, 140, 80, 30);jf.setVisible(true);jf.setSize(460,350);jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); }@Overridepublic void actionPerformed(ActionEvent e){if(e.getSource()==btn000){String a=txt2.getText();if(a.equals("")){txt2.setText("");}else{txt2.setText(a+"0");}}if(e.getSource()==btn001)txt2.setText(txt2.getText()+"1");}if(e.getSource()==btn002){txt2.setText(txt2.getText()+"2");}if(e.getSource()==btn003){ txt2.setText(txt2.getText()+"3"); } if(e.getSource()==btn004){ txt2.setText(txt2.getText()+"4"); } if(e.getSource()==btn005){ txt2.setText(txt2.getText()+"5"); } if(e.getSource()==btn006){ txt2.setText(txt2.getText()+"6"); } if(e.getSource()==btn007){ txt2.setText(txt2.getText()+"7"); } if(e.getSource()==btn008){ txt2.setText(txt2.getText()+"8"); } if(e.getSource()==btn009){ txt2.setText(txt2.getText()+"9"); } if(e.getSource()==btn100){ txt2.setText("100"); }if(e.getSource()==btn200){ txt2.setText("200"); }if(e.getSource()==btn300){ txt2.setText("300"); }if(e.getSource()==btn500){ txt2.setText("500"); }if(e.getSource()==btn1000){ txt2.setText("1000"); }//返回if(e.getSource()==btnback2){Default defa=new Default();defa.defaltDemo();jf.dispose();}//重输if(e.getSource()==btn0010){txt2.setText("");}//取款确定if(e.getSource()==btnsure1)。

相关文档
最新文档