Java实训项目——网银管理系统(2021大一下)

文章目录

  • 前言
  • 一、内容介绍
  • 二、实现原理
    • 登录页面
    • 注册页面
    • 首页
    • 用户信息
    • 修改密码
    • 添加银行卡
    • 银行卡查看
    • 充值
    • 提现
    • 银行卡转账
    • 用户管理
  • 代码展示
    • BanksController
    • UserController
    • AdminDao
    • BanksDao
    • UserDao
    • Admin
    • Banks
    • User
    • BanksServiceImpl
    • UsersServiceImpl
    • BanksService接口
    • UserService接口
    • AppStar测试类
    • AddBanksMoneyView
    • AddBanksView
    • AddUsersMoneyView
    • AddUserView
    • MainView
    • MoveMoneyView
    • ShowBanksView
    • ShowUserView
    • UpdatePwdView
    • UserLoginView
    • UsersView
  • 总结
    • 拒绝白嫖,给个三连吧!


前言

用到了IO流,集合和JavaSwing的实训小项目


一、内容介绍

基本内容有:

  1. 登陆

  2. 注册

  3. 首页

  4. 个人信息显示

  5. 修改密码

  6. 添加银行卡

  7. 银行卡查看

  8. 充值

  9. 提现

  10. 转账

  11. 用户管理

主要用到的知识如下:

集合知识:用到List集合,来运输暂存数据 。
接口:创建了BankController接口和UserController接口方便方法的调用和创建,分别用BankControllerimpl和UserControllerimpl类实现了它们。
创建实体类:实用了创建方法的快捷方式。
IO流:运用对象流的序列化和反序列化,将集合多次存入取出文件,方便数据更新的同时,能有效的保存用户和银行卡的信息。实现的此代码的类有AdminDao,BanksDao,UserDao。
JavaSwing:把GUI组件合理的搭配和设计,添加到底层容器中,展现到窗口中,然后添加监听器,处理事件,完成每个界面的功能。此部分技术的运用都在com.baizhi.view包中

二、实现原理

登录页面

首先设计的是登录页面,设置了手机号和密码两个可填项,同时设置两个按钮并且对其设置监听器,点击等录能够进入主页面,点击注册则跳转注册页面。
Java实训项目——网银管理系统(2021大一下)_第1张图片

注册页面

注册页面设置了一些用户的属性,没有格式要求,填写完整即可点击提交,把数据通过AdminDao对象流存入文件Admin.data,注册完成自动关闭页面,再次登录就可以使用该账号登录,点击取消关闭页面。
Java实训项目——网银管理系统(2021大一下)_第2张图片

首页

主页面包含左侧导航栏功能列表,显示功能,而功能这可以在界面中间部分展示出来,点击首页,返回首页,对应的界面是MainView。
Java实训项目——网银管理系统(2021大一下)_第3张图片

用户信息

有用户的信息展示,包括金额,修改金额后此处的金额也会随之变动,文字的前面都有图片标签。此页面的类为ShowUserView。

Java实训项目——网银管理系统(2021大一下)_第4张图片

修改密码

此功能是给登录的用户从新设置密码,通过UserDao类,获取所有用户,然后通过list集合存取用户,通过对list的遍历筛选,得到本用户的密码,然后调用setPwd对用户密码进行修改。
Java实训项目——网银管理系统(2021大一下)_第5张图片

添加银行卡

与注册用户相似,也是把得到的银行卡信息存到list中,如果已有银行卡,则先把以前银行卡的内容存到list中,然后再把新增的信息存入,这样就可以一次性存完,不用再考虑信息存入文件的内容覆盖的问题了。点击提交,存入数据。此页面的类为AddBanksView。

Java实训项目——网银管理系统(2021大一下)_第6张图片

银行卡查看

在此页面可以观察到此账户拥有的银行卡的信息,同样是通过BankDao获取此手机号拥有的银行卡信息list集合,然后通过遍历打印出来。此类的为ShowBanksView。
Java实训项目——网银管理系统(2021大一下)_第7张图片

充值

充值是从银行卡充钱到账户上,实现金额交换,将文本框获取的mony属性通过构造方法传入BanksServiceImpl类,完成后端的文件中的集合,然后通过遍历寻找,修改,然后点击充值,便会实现金额交换。此类为AddUsersMoneyView。
Java实训项目——网银管理系统(2021大一下)_第8张图片

提现

提现就是把账户上的钱提到银行卡上。
提现和充值相同,把二者的方法,交换重写一遍就可以实现次功能。此类为AddBanksMoneyView。

Java实训项目——网银管理系统(2021大一下)_第9张图片

银行卡转账

首先要选择转入转出的对象是银行卡还是账户,然后分别输入银行卡或是账户的卡号和手机号,然后遍历所给的号是否存在,不存在会有弹框提示
确定存在后,会对转出和转入方两个方法同时调用。实现金钱交换。
此类为MoveMoneyView。
Java实训项目——网银管理系统(2021大一下)_第10张图片

用户管理

在这里可以显示注册过的所有用户,与银行卡查看同理,都是先得到所有用户信息的list,然后遍历打印出来。此类为ShowUserView。
Java实训项目——网银管理系统(2021大一下)_第11张图片

代码展示

Java实训项目——网银管理系统(2021大一下)_第12张图片

BanksController

package com.baizhi.controller;

import com.baizhi.entity.Banks;
import com.baizhi.service.BanksService;
import com.baizhi.service.impl.BanksServiceImpl;

import java.util.List;

public class BanksController {
    private BanksServiceImpl service =new BanksServiceImpl();
    public boolean addBanks(Banks banks){
        return service.addBanks(banks);
    }
    public List<Banks> showBanksByTel(String tel){
        return service.showBanksByTel(tel);
    }
    public boolean deleteMoney(String banksNum,double money){
        return service.deleteMoney(banksNum,money);
    }
    public boolean addMoney(String banksNum,double money){
        return service.addMoney(banksNum,money);
    }
    public boolean moveMoney(String banksNum1,String banksNum2,double money){
        return  service.moveMoney(banksNum1,banksNum2,money);
    }


    public boolean chickNUm( String num) {
        return  service.chickNUm(num);
    }
}

UserController

package com.baizhi.controller;

import com.baizhi.entity.Banks;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.service.impl.UsersServiceImpl;

import java.util.List;

// 用户管理
public class UserController {
    private UserService userService =new UsersServiceImpl();
    public User userLog(String tel,String pwd) {

        return userService.findUSerByTelAdnpwd(tel,pwd);
    }
//    注册
//String name, String cardNum, String tel, String pwd, String email, double money, String relName
    public boolean addUser(String name, String cardNum, String tel, String pwd, String email, String relName){
        User u =new User(name,cardNum,tel,pwd,email,0,relName);
        return userService.addUsers(u);
    }

    public boolean isExistTel(String tel) {
        return userService.isExistTel(tel);
    }
    public boolean isExistEmail(String email){
        return userService.isExistEmail(email);
    }


    public boolean updatePwd(String tel,String odlPwd,String pwd){
        return userService.updatePwd(tel,pwd);
    }
    public boolean addMoney(String tel,double money){

        return userService.addMoney(tel,money);
    }
    public boolean deleteMoney(String tel,double money){
        return userService.deleteMoney(tel,money);
    }
    public List<User> showUserTel(String tel){
        return userService.showUserTel(tel);
    }
    public List<User> showUser(){
        return userService.showUser();
    }

    public boolean chickNUm(String num) {
        return userService.chickNUm(num);}
}

AdminDao

package com.baizhi.dao;
import com.baizhi.entity.Admin;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class AdminDao {
    public List<Admin> read(){
        List<Admin> list =new ArrayList<>();
        try{

            ObjectInputStream IS=new ObjectInputStream(new FileInputStream("admin.data"));
            list = (List<Admin>) IS.readObject();
            IS.close();
        }catch (Exception e){
            e.printStackTrace();

        }
        return list;
    }

    public boolean write(List<Admin> list){
        try {
            ObjectOutputStream OS = new ObjectOutputStream(new FileOutputStream("admin.data"));
            OS.writeObject(list);
            OS.close();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("写入失败");
            return false;
        }
    }

    public static void main(String[] args) {
        List<Admin> list =new ArrayList<>();
        list.add(new Admin("admin","123"));
        AdminDao dao =new AdminDao();
        dao.write(list);
        List<Admin> lists =dao.read();
        for (Admin ad : lists){
            System.out.println(ad);
        }
    }
}

BanksDao

package com.baizhi.dao;

import com.baizhi.entity.Banks;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class BanksDao {
    public List<Banks> read(){
        List<Banks> list =new ArrayList<>();
        try {
            FileInputStream file =new FileInputStream("Banks.data");
            ObjectInputStream IS =new ObjectInputStream(file);
            list = (List<Banks>) IS.readObject();
            IS.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }
    public boolean write(List<Banks> list){
        try {
            FileOutputStream file=new FileOutputStream("Banks.data");
            ObjectOutputStream OS =new ObjectOutputStream(file);
            OS.writeObject(list);
            OS.close();
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }

}

UserDao

package com.baizhi.dao;

import com.baizhi.entity.Admin;
import com.baizhi.entity.User;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class UserDao {
    public List<User> read(){
        List<User> list =new ArrayList<>();
        try{
            ObjectInputStream IS=new ObjectInputStream(new FileInputStream("User.data"));
            list = (List<User>) IS.readObject();
            IS.close();
        }catch (Exception e){
            e.printStackTrace();

        }
        return list;
    }
    public boolean write(List<User> list){
     try {
        ObjectOutputStream OS = new ObjectOutputStream(new FileOutputStream("User.data"));
        OS.writeObject(list);
        OS.close();
        return true;
    }catch (Exception e){
        e.printStackTrace();
        System.out.println("写入失败");
        return false;
    }
}


}

Admin

package com.baizhi.entity;

import java.io.Serializable;

public class Admin  implements Serializable {
    private String account;
    private String pwd;

    public Admin(String account, String pwd) {
        this.account = account;
        this.pwd = pwd;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "account='" + account + '\'' +
                ", pwd='" + pwd + '\'' +
                '}';
    }
}

Banks

package com.baizhi.entity;

import javax.swing.*;
import java.io.Serializable;

public class Banks implements Serializable {
    private String bankNumber;
    private double money;
    private String bankName;
    private String tel;

    public Banks(String bankNumber, double money, String bankName, String tel) {
        this.bankNumber = bankNumber;
        this.money = money;
        this.bankName = bankName;
        this.tel = tel;
    }

    public String getBankNumber() {
        return bankNumber;
    }

    public void setBankNumber(String bankNumber) {
        this.bankNumber = bankNumber;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @Override
    public String toString() {
        return "Banks{" +
                "bankNumber='" + bankNumber + '\'' +
                ", money=" + money +
                ", bankName='" + bankName + '\'' +
                ", tel='" + tel + '\'' +
                '}';
    }
}

User

package com.baizhi.entity;

import java.io.Serializable;

public class User implements Serializable {
    private String name;
    private String cardNum;
    private String tel;
    private String pwd;
    private String email;
    private double money;
    private String relName;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCardNum() {
        return cardNum;
    }

    public void setCardNum(String cardNum) {
        this.cardNum = cardNum;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public String getRelName() {
        return relName;
    }

    public void setRelName(String relName) {
        this.relName = relName;
    }

    public User(String name, String cardNum, String tel, String pwd, String email, double money, String relName) {
        this.name = name;
        this.cardNum = cardNum;
        this.tel = tel;
        this.pwd = pwd;
        this.email = email;
        this.money = money;
        this.relName = relName;
    }

    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", cardNum='" + cardNum + '\'' +
                ", tel='" + tel + '\'' +
                ", pwd='" + pwd + '\'' +
                ", email='" + email + '\'' +
                ", money=" + money +
                ", relName='" + relName + '\'' +
                '}';
    }
}

BanksServiceImpl

package com.baizhi.service.impl;

import com.baizhi.dao.BanksDao;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;
import com.baizhi.service.BanksService;

import java.util.ArrayList;
import java.util.List;

public class BanksServiceImpl implements BanksService {
    private BanksDao dao =new BanksDao();
    private  List<Banks> list;
    @Override
    public boolean addBanks(Banks banks) {
         list =new ArrayList<>();
         list= dao.read();
         list.add(banks);
        return dao.write(list);
    }

    @Override
    public List<Banks> showBanksByTel(String tel) {
        List<Banks> list=dao.read();
        List<Banks> uList=new ArrayList<>();
        for (Banks b:list){
            if (b.getTel().equals(tel)) {
                uList.add(b);
            }

        }
        return uList;
    }

    @Override
    public boolean deleteMoney(String banksNum, double money) {
        List<Banks> list=dao.read();
        for (Banks b:list){
            System.out.println("长度"+list.size());
                if (banksNum.equals(b.getBankNumber())){
                    double mo =b.getMoney();
                    if (mo-money<0){
                        return false;
                    }else {
                        b.setMoney(mo-money);
                        System.out.println("银行卡减后"+b.getMoney());
                    }
                }
            }
        return dao.write(list);
        }

    @Override
    public boolean moveMoney(String banksNum1, String banksNum2, double money) {
        List<Banks> list =dao.read();
        //System.out.println("出账户"+banksNum1+",入账户"+banksNum2);
        for (Banks b: list) {


            if (b.getBankNumber().equals(banksNum1) ) {
                if (b.getMoney()-money>=0)
                b.setMoney(b.getMoney() - money);
                else return false;
            }
        }
            for (Banks b:list){
            if (b.getBankNumber().equals(banksNum2)){
                b.setMoney(b.getMoney()+money);
            }

        }
        return dao.write(list);
    }

    @Override
    public boolean chickNUm(String num) {
        List<Banks> list =dao.read();
        for (Banks b:list){
             if (b.getBankNumber().equals(num)){
                 return true;
             }
        }
        return false;
    }

    public boolean addMoney(String banksNum, double money) {
        List<Banks> list =dao.read();
        for (Banks b:list){
            if (b.getBankNumber().equals(banksNum)){
                System.out.printf("银行余额(+):"+b.getMoney());
                b.setMoney(b.getMoney()+money);
            }
        }
        return dao.write(list);
    }
}

UsersServiceImpl

package com.baizhi.service.impl;

import com.baizhi.dao.UserDao;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.w3c.dom.ls.LSInput;

import java.util.ArrayList;
import java.util.List;

public class UsersServiceImpl implements UserService {

    private UserDao dao =new UserDao();

    @Override
    public User findUSerByTelAdnpwd(String tel, String pwd) {
        List<User> list =dao.read();
        for (User U:list){
            if(U.getTel().equals(tel)&&U.getPwd().equals(pwd)){
                System.out.println("登录成功!");
                return U;
            }
        }
        return null;
    }

    @Override
    public boolean addUsers(User user) {
        List<User> list =dao.read();
        list.add(user);
        return dao.write(list);
    }

    @Override
    public boolean isExistTel(String tel) {
        List<User> list =dao.read();
        for(User u:list){
            if(u.getTel().equals(tel)){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean isExistEmail(String email) {
        List<User> list =dao.read();
        for (User u:list){
            if(u.getEmail().equals(email)){
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean updatePwd(String tel, String pwd) {
        List<User> list =dao.read();
        for (User user: list){
            String uTel = user.getTel();
            if ((uTel).equals(tel)){
                user.setPwd(pwd);
                break;
            }
        }
        return dao.write(list);
    }

    @Override
    public boolean addMoney(String tel, double money) {
        List<User> list =dao.read();
        for (User user:list){
            if (user.getTel().equals(tel)){
                user.setMoney(user.getMoney()+money);
                System.out.println(user.getMoney());
            }
        }

        return dao.write(list);
    }

    public boolean deleteMoney(String tel, double money) {

        List<User> list=dao.read();

        for (User user:list){
            if (tel.equals(user.getTel())){

                double mo =user.getMoney();
                if (mo-money<0){
                    return false;
                }else {
                    System.out.println(user.getMoney());
                    user.setMoney(mo-money);
                    System.out.println(user.getMoney());

                }
            }

        }


        return dao.write(list);
    }

    @Override
    public List<User> showUserTel(String tel) {
        return null;
    }

    @Override
    public List<User> showUser() {
        List<User> list=dao.read();
        return list;
    }

    @Override
    public boolean chickNUm(String num) {
        List<User>list=dao.read();
        for (User user:list){
           if (user.getTel().equals(num)){
               return true;
           }
        }
        return false;
    }


    public List<User> showUserTel() {
        List<User> list=dao.read();
        List<User> uList=new ArrayList<>();

        return uList;
    }

}

BanksService接口

package com.baizhi.service;

import com.baizhi.entity.Banks;

import java.util.List;

public interface BanksService {
    public boolean addBanks(Banks banks);
    public List<Banks> showBanksByTel(String tel);
    public boolean deleteMoney(String banksNum,double money);
    boolean moveMoney(String banksNum1, String banksNum2, double money);
    boolean chickNUm(String num);
}

UserService接口

package com.baizhi.service;

import com.baizhi.entity.Banks;
import com.baizhi.entity.User;

import java.util.List;

public interface UserService  {

    public User findUSerByTelAdnpwd(String tel,String pwd);
    public boolean addUsers(User user);
    public boolean isExistTel(String tel);
    public boolean isExistEmail(String email);

    public boolean updatePwd(String tel,String pwd);

    public boolean addMoney(String tel,double money);

    boolean deleteMoney(String tel, double money);
    public List<User> showUserTel(String tel);
    public List<User> showUser();
    boolean chickNUm(String num);
}

AppStar测试类

package com.baizhi.test;

import com.baizhi.view.UserLoginView;

public class AppStar {
    public static void main(String[] args) {
        UserLoginView u =new UserLoginView();
    }
}

AddBanksMoneyView

package com.baizhi.view;

import com.baizhi.controller.BanksController;
import com.baizhi.controller.UserController;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

public class AddBanksMoneyView extends JPanel implements MouseListener {

    private JPanel top,bom;
    private JLabel moneyJL,banksNumJL;
    private JTextField moneyJF;
    private JComboBox banksNumJB;
    private JButton sub;
    private User user;
    public AddBanksMoneyView(User user, List<Banks> list){

        this.user=user;
        this.setLayout(new BorderLayout());
        top =new JPanel();
        top.setLayout(new GridLayout(2,2,20,20));

        moneyJL=new JLabel("请输入提现金额:",JLabel.CENTER);
        moneyJF=new JTextField(20);
        top.add(moneyJL);
        top.add(moneyJF);

        banksNumJL =new JLabel("请选择提现银行卡号",JLabel.CENTER);
        banksNumJB =new JComboBox();
        banksNumJB.addItem("---请选择---");
        for (Banks b: list){
            banksNumJB.addItem(b.getBankNumber());
        }
        top.add(banksNumJL);
        top.add(banksNumJB);
        this.add(top,BorderLayout.CENTER);

        bom =new JPanel();
        sub =new JButton("提现");
        sub.addMouseListener(this);
        bom.add(sub);
        this.add(bom,BorderLayout.SOUTH);

    }


    @Override
    public void mouseClicked(MouseEvent e) {
        String moneys=moneyJF.getText();
        String banksNum=banksNumJB.getSelectedItem().toString();
       // System.out.println("这是卡号"+banksNum+",提现"+);
        if (moneys.equals("")){
            JOptionPane.showMessageDialog(null,"金额不能为空!");
            return;
        }
        else if("---请选择---".equals(banksNum)){
            JOptionPane.showMessageDialog(null,"请选择银行卡!");
            return;
        }

        try {
            double money = Double.parseDouble(moneys);
            if (money <= 0) {
                JOptionPane.showMessageDialog(null, "充值金额要大于0!");
                return;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "请输入数字!");
            return;
        }

        double money =Double.parseDouble(moneys);
        BanksController banksController =new BanksController();
        UserController userController=new UserController();
        boolean flag= userController.deleteMoney(user.getTel(), money);
        if(flag){
            banksController.addMoney(banksNum,money);
            JOptionPane.showMessageDialog(null,"提现成功");
            return;
        }else {
            JOptionPane.showMessageDialog(null,"账户余额不足,提现失败!");
            return;
        }
    }
    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

AddBanksView

package com.baizhi.view;

import com.baizhi.controller.BanksController;
import com.baizhi.dao.BanksDao;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;
import jdk.nashorn.internal.scripts.JO;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class AddBanksView extends JPanel implements MouseListener {
    private User user;
    private JPanel top,bom;
    private JLabel bankNumJL, moneyJL, bankNameJL;
    private JTextField bankNumJF,moneyJF,bankNameJF;
    private JButton sub;
    public AddBanksView(User user){
        this.user=user;
        this.setLayout(new BorderLayout());
        top=new JPanel();
        top.setLayout(new GridLayout(3,2,20,20));

        bankNumJL =new JLabel("卡号:",JLabel.CENTER);
        bankNumJF=new JTextField(20);
        top.add(bankNumJL);
        top.add(bankNumJF);

        bankNameJL =new JLabel("开户行",JLabel.CENTER);
        bankNameJF=new JTextField(20);
        top.add(bankNameJL);
        top.add(bankNameJF);

        moneyJL=new JLabel("余额",JLabel.CENTER);
        moneyJF=new JTextField(20);
        top.add(moneyJL);
        top.add(moneyJF);
        this.add(top,BorderLayout.CENTER);
        bom=new JPanel();
        sub =new JButton("提交");
        sub.setName("sub");
        sub.addMouseListener(this);
        bom.add(sub);
        this.add(bom,BorderLayout.SOUTH);

    }

    @Override
    public void mouseClicked(MouseEvent e) {
        String bankNum=bankNumJF.getText();
        String money =moneyJF.getText();
        //double bankName =Double.parseDouble(bankNumJF.getText());
        String bankName=bankNameJF.getText();
        if (bankNum.equals("")){
            JOptionPane.showMessageDialog(null,"卡号不能为空");
            bankNameJF.setText("");
            bankNumJF.setText("");
            moneyJF.setText("");
        }
        if (money.equals("")){
            JOptionPane.showMessageDialog(null,"余额不能为空");
            bankNameJF.setText("");
            bankNumJF.setText("");
            moneyJF.setText("");
        }
        if (bankName.equals("")){
            JOptionPane.showMessageDialog(null,"开户行不能为空");
            bankNameJF.setText("");
            bankNumJF.setText("");
            moneyJF.setText("");
        }

        double mo=Double.parseDouble(money);
        BanksController b =new BanksController();
        Banks banks =new Banks(bankNum,mo,bankName,user.getTel());
        boolean flag =b.addBanks(banks);
        if (flag){
            JOptionPane.showMessageDialog(null,"添加成功!");
            bankNameJF.setText("");
            bankNumJF.setText("");
            moneyJF.setText("");
        }else {
            JOptionPane.showMessageDialog(null,"添加失败!");
            bankNameJF.setText("");
            bankNumJF.setText("");
            moneyJF.setText("");
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

AddUsersMoneyView

package com.baizhi.view;

import com.baizhi.controller.BanksController;
import com.baizhi.controller.UserController;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

public class AddUsersMoneyView extends JPanel implements MouseListener {
    private JPanel top,bom;
    private JLabel moneyJL,banksNumJL;
    private JTextField moneyJF;
    private JComboBox banksNumJB;
    private JButton sub;
    private User user;
    public AddUsersMoneyView(User user, List<Banks> list){

         this.user=user;
         this.setLayout(new BorderLayout());
         top =new JPanel();
         top.setLayout(new GridLayout(2,2,20,20));

         moneyJL=new JLabel("请输入充值金额:",JLabel.CENTER);
         moneyJF=new JTextField(20);
         top.add(moneyJL);
         top.add(moneyJF);

         banksNumJL =new JLabel("请选择充值账户",JLabel.CENTER);
            banksNumJB =new JComboBox();
            banksNumJB.addItem("---请选择---");
            for (Banks b: list){
                banksNumJB.addItem(b.getBankNumber());
            }
            top.add(banksNumJL);
            top.add(banksNumJB);
            this.add(top,BorderLayout.CENTER);

            bom =new JPanel();
            sub =new JButton("充值");
            sub.addMouseListener(this);
            bom.add(sub);
            this.add(bom,BorderLayout.SOUTH);

    }



    @Override
    public void mouseClicked(MouseEvent e) {
        String moneys=moneyJF.getText();
        String banksNum=banksNumJB.getSelectedItem().toString();
        if (moneys.equals("")){
            JOptionPane.showMessageDialog(null,"金额不能为空!");
            return;
        }

        else if("---请选择---".equals(banksNum)){
            JOptionPane.showMessageDialog(null,"请选择银行卡!");
            return;
        }

            try {
                double money = Double.parseDouble(moneys);
                if (money <= 0) {
                    JOptionPane.showMessageDialog(null, "充值金额要大于0!");
                    return;
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "请输入数字!");
                return;
            }

        double money =Double.parseDouble(moneys);
        BanksController banksController =new BanksController();
        UserController userController=new UserController();
        boolean flag=banksController.deleteMoney(banksNum,money);
        if(flag){
                    userController.addMoney(user.getTel(), money);
                    JOptionPane.showMessageDialog(null,"充值成功");
                    return;
        }else {
            JOptionPane.showMessageDialog(null,"银行卡余额不足,请更换银行卡!");
            return;
        }
    }
    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

AddUserView

package com.baizhi.view;

import com.baizhi.controller.UserController;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class AddUserView extends Dialog implements MouseListener {
    private JPanel jp;
    private JLabel telJL,pwdJL,nameJL,relnameJL,cardNumJL,emailJL;
    private JTextField telJF,nameJF,relnameJF,cardNumJF,emailJF;
    private JPasswordField pwdJF;
    private JButton sub,clo;

    public AddUserView (Frame owner){
        super(owner);
        jp= new JPanel();
        jp.setBackground(Color.pink);
        jp.setBorder(new EmptyBorder(20,20,20,20));
        jp.setLayout(new GridLayout(10,2,20,20));
        EmptyBorder job =new EmptyBorder(0,20,0,0);
        EmptyBorder fbo =new EmptyBorder(0,0,0,0);
        telJL =new JLabel("手机号",JLabel.LEFT);
        telJL .setIcon(new ImageIcon("img/phone_icon.png"));
        telJL.setBorder(job);
        telJF =new JTextField(20);
        telJF.setBorder(fbo);
        jp.add(telJL);
        jp.add(telJF);

        pwdJL =new JLabel("密码",JLabel.LEFT);
        pwdJL .setIcon(new ImageIcon("img/password_icon.png"));
        pwdJL.setBorder(job);
        pwdJF = new JPasswordField(20);
        pwdJF.setBorder(fbo);
        jp.add(pwdJL);
        jp.add(pwdJF);

       nameJL =new JLabel("昵称",JLabel.LEFT);
        nameJL .setIcon(new ImageIcon("img/name_icon.png"));
        nameJL.setBorder(job);
        nameJF =new JTextField(20);
        nameJF.setBorder(fbo);
        jp.add(nameJL);
        jp.add(nameJF);

        relnameJL =new JLabel("真实姓名",JLabel.LEFT);
        relnameJL .setIcon(new ImageIcon("img/username_icon.png"));
        relnameJL.setBorder(job);
        relnameJF =new JTextField(20);
        relnameJF.setBorder(fbo);
        jp.add(relnameJL);
        jp.add(relnameJF);

        cardNumJL =new JLabel("身份证号",JLabel.LEFT);
        cardNumJL .setIcon(new ImageIcon("img/idc_icon.png"));
        cardNumJL.setBorder(job);
        cardNumJF =new JTextField(20);
        cardNumJF.setBorder(fbo);
        jp.add(cardNumJL);
        jp.add(cardNumJF);

        emailJL =new JLabel("邮箱",JLabel.LEFT);
        emailJL .setIcon(new ImageIcon("img/msg_icon.png"));
        emailJL.setBorder(job);
        emailJF =new JTextField(20);
        emailJF.setBorder(fbo);
        jp.add(emailJL);
        jp.add(emailJF);

        sub =new JButton("提交");
        sub.setName("sub");
        sub.addMouseListener(this);
        jp.add(sub);
        clo=new JButton("取消");
        clo.setName("clo");
        clo.addMouseListener(this);
        jp.add(clo);
        this.add(jp);


        this.setSize(400,500);
        this.setIconImage(new ImageIcon("img/tubiao_qiaozhi.jpg").getImage());
        this.setLocationRelativeTo(null);  //居中
        this.setVisible(true);
        this.setTitle("百知转账管理系统-->用户注册");
        this.setResizable(false);
       // super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    @Override
    public void mouseClicked(MouseEvent e) {
        String str = e.getComponent().getName();
        switch (str) {
            case "sub":
//                String name, String cardNum, String tel, String pwd, String email, double money, String relName
                String tel =telJF.getText();
                String pwd= new String(pwdJF.getPassword());
                String name=nameJF.getText();
                String relName=cardNumJF.getText();
                String cardNUm=cardNumJF.getText();
                String email=emailJF.getText();
                if (tel.equals("")){
                    JOptionPane.showMessageDialog(null,"手机号不能为空!");
                    break;
                }
                else if (pwd.equals("")){
                    JOptionPane.showMessageDialog(null,"密码不能为空!");
                    break;
                }
                else if (name.equals("")){
                    JOptionPane.showMessageDialog(null,"昵称不能为空!");
                    break;
                }
                else if (relName.equals("")){
                    JOptionPane.showMessageDialog(null,"真实姓名不能为空!");
                    break;
                }
                else if (cardNUm.equals("")){
                    JOptionPane.showMessageDialog(null,"身份证号不能为空!");
                    break;
                }
                else if (email.equals("")){
                    JOptionPane.showMessageDialog(null,"邮箱不能为空!");
                    break;
                }
                UserController con =new UserController();
                if (con.isExistEmail(tel)){

                    JOptionPane.showMessageDialog(null,"手机号已被注册");
                    break;
                }
                else if (con.isExistEmail(email)){

                    JOptionPane.showMessageDialog(null,"邮箱已被注册");
                    break;
                }
                else if (con.isExistEmail(cardNUm)){

                    JOptionPane.showMessageDialog(null,"身份证号被注册");
                    break;
                }

                boolean flag =con.addUser(tel,pwd,name,relName,cardNUm,email);
                if (flag){
                    JOptionPane.showMessageDialog(null,"注册成功!");
                    dispose();
                }else {
                    JOptionPane.showMessageDialog(null,"注册失败!");
                }

                break;
            case "clo":
                dispose();
                break;
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

MainView

package com.baizhi.view;

import com.baizhi.controller.BanksController;
import com.baizhi.controller.UserController;
import com.baizhi.entity.Banks;
import com.baizhi.entity.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

public class MainView extends JFrame implements MouseListener {
    private User user;

    private  JPanel jpJP,topJP,leftJP,conJP,indexJP;
    private  JLabel logoJL,welJL,indexJL;
    private JButton indexJB,showUserJB,pwdJB,banksJB,addMoneyJB,deleteMoneyJB,moveMoneyJB,updateUserJB,addBanksJB;


    public MainView(User user){

        jpJP=new JPanel();
        jpJP.setLayout(new BorderLayout());

        topJP =new JPanel();
        logoJL=new JLabel();
        //logoJL.setIcon(new ImageIcon("img/logo.png"));
        ImageIcon lo =new ImageIcon("img/logo.png");
        lo.setImage(lo.getImage().getScaledInstance(120,30,Image.SCALE_DEFAULT));
        logoJL.setIcon(lo);
        welJL=new JLabel("欢迎用户:"+user.getName());
        topJP.add(welJL);
        topJP.add(logoJL);
        jpJP.add(topJP,BorderLayout.NORTH);
        //左侧导航
        leftJP=new JPanel();
        leftJP.setLayout(new GridLayout(10,1,20,7));
        EmptyBorder jb =new EmptyBorder(20,15,10,20);
        indexJB =new JButton("首页");
        indexJB.setForeground(Color.BLUE);
        indexJB.setName("indexJB");
        indexJB.setBorder(jb);
        indexJB.addMouseListener(this);
        leftJP.add(indexJB);

        showUserJB =new JButton("用户信息");
        showUserJB.setForeground(Color.BLUE);
        showUserJB.setName("showUserJB");
        showUserJB.setBorder(jb);
        showUserJB.addMouseListener(this);
        leftJP.add(showUserJB);

        pwdJB =new JButton("修改密码");
        pwdJB.setForeground(Color.BLUE);
        pwdJB.setName("pwdJB");
        pwdJB.setBorder(jb);
        pwdJB.addMouseListener(this);
        leftJP.add(pwdJB);

        addBanksJB =new JButton("添加银行卡");
        addBanksJB.setForeground(Color.BLUE);
        addBanksJB.setName("addBankJB");
        addBanksJB.setBorder(jb);
        addBanksJB.addMouseListener(this);
        leftJP.add(addBanksJB);

        banksJB =new JButton("银行卡");
        banksJB.setForeground(Color.BLUE);
        banksJB.setName("banksJB");
        banksJB.setBorder(jb);
        banksJB.addMouseListener(this);
        leftJP.add(banksJB);

       addMoneyJB =new JButton("充值");
        addMoneyJB.setForeground(Color.BLUE);
        addMoneyJB.setName("addMoneyJB");
        addMoneyJB.setBorder(jb);
        addMoneyJB.addMouseListener(this);
        leftJP.add(addMoneyJB);


        deleteMoneyJB =new JButton("提现");
        deleteMoneyJB.setForeground(Color.BLUE);
        deleteMoneyJB.setName("deleteMoneyJB");
        deleteMoneyJB.setBorder(jb);
        deleteMoneyJB.addMouseListener(this);
        leftJP.add(deleteMoneyJB);

       moveMoneyJB =new JButton("转账");
        moveMoneyJB.setForeground(Color.BLUE);
        moveMoneyJB.setName("moveMoneyJB");
        moveMoneyJB.setBorder(jb);
        moveMoneyJB.addMouseListener(this);
        leftJP.add(moveMoneyJB);


        updateUserJB =new JButton("用户管理");
        updateUserJB.setForeground(Color.BLUE);
        updateUserJB.setName("updateUserJB");
        updateUserJB.setBorder(jb);
        updateUserJB.addMouseListener(this);
        leftJP.add(updateUserJB);

        jpJP.add(leftJP,BorderLayout.WEST);
        conJP=new JPanel();
        conJP.setBorder(new EmptyBorder(10,10,10,10));

        indexJP =new JPanel();
        indexJP.setSize(400,400);
        indexJL=new JLabel();
        ImageIcon icon =new ImageIcon("img/banner1.jpg");
        icon.setImage(icon.getImage().getScaledInstance(450,350,Image.SCALE_DEFAULT));
        indexJL.setIcon(icon);
        indexJP.add(indexJL);
        conJP.add(indexJP);
        jpJP.add(conJP);

        this.add(jpJP);

        this.user=user;
        this.setIconImage(new ImageIcon("img/tubiao_peiqi.jpg").getImage());
        this.setSize(630,480);
        this.setLocationRelativeTo(null);  //居中
        this.setVisible(true);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public void  updateView(JPanel jp){
        conJP.removeAll();
        conJP.add(jp);
        conJP.validate();
        conJP.updateUI();
    }


    @Override
    public void mouseClicked(MouseEvent e) {
//        JButton indexJB,showUserJB,pwdJB,banksJB,addMoneyJB,deleteMoneyJB,moveMoneyJB,updateUserJB;
        String str =e.getComponent().getName();
        switch (str){
            case "indexJB":
                updateView(indexJP);
                break;
            case "showUserJB":
                UserController userController0 =new UserController();
                List<User> list0 = userController0.showUser();
                ShowUserView showUserView =new ShowUserView(user,list0);
                updateView(showUserView);
                break;
            case "pwdJB":
                //System.out.println("11111");
                UpdatePwdView updatePwdView =new UpdatePwdView(user);
                updateView(updatePwdView);
                break;
            case  "addBankJB":

                AddBanksView addBanksView=new AddBanksView(user);
                updateView(addBanksView);
                    break;

            case  "banksJB":
                BanksController banksController =new BanksController();
                List<Banks> list = banksController.showBanksByTel(user.getTel());
                ShowBanksView showBanksView=new ShowBanksView(list);
                updateView(showBanksView);
                break;
            case "addMoneyJB":
                BanksController banksController1 =new BanksController();
                List<Banks> lists =banksController1.showBanksByTel(user.getTel());
                AddUsersMoneyView addUsersMoneyView =new AddUsersMoneyView(user,lists);
                updateView(addUsersMoneyView);
                break;
            case "deleteMoneyJB":
                BanksController banksController2 =new BanksController();
                List<Banks> listss =banksController2.showBanksByTel(user.getTel());
                AddBanksMoneyView addBanksMoneyView =new AddBanksMoneyView(user,listss);
                updateView(addBanksMoneyView);
                break;
            case "moveMoneyJB":
                BanksController banksController3 =new BanksController();
                List<Banks> listsss =banksController3.showBanksByTel(user.getTel());
                MoveMoneyView moveMoneyView =new MoveMoneyView(listsss);
                updateView(moveMoneyView);
                break;
            case "updateUserJB":
                UserController userController =new UserController();
                List<User> list1 = userController.showUser();
                UsersView usersView =new UsersView(list1);
                updateView(usersView);
                break;
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

MoveMoneyView

package com.baizhi.view;

import com.baizhi.controller.BanksController;
import com.baizhi.controller.UserController;
import com.baizhi.entity.Banks;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

public class MoveMoneyView extends JPanel implements MouseListener {
    ImageIcon icon;
    Image img;

    private Box boxV,boxH,boxH1,boxH2,boxH3,boxH4;
    private JLabel inMoneyJL,outMoneyJL,moneyJL,topJL,inMoneyNumJL,outMoneyNumJL;
    private JTextField moneyJF,outMoneyJF,inMoneyJF;
    private JButton stu;
    private JComboBox inMoneyJC,outMoneyJC;

public MoveMoneyView(List<Banks> list) {
    icon=new ImageIcon("img/bg2.png");
    img=icon.getImage();

    boxH=Box.createHorizontalBox();
    boxH1=Box.createHorizontalBox();
    boxH2=Box.createHorizontalBox();
    boxH3=Box.createHorizontalBox();
    boxH4=Box.createHorizontalBox();
    boxV=Box.createVerticalBox();


    topJL =new JLabel("银行卡转账");
    topJL.setFont(new Font("微软雅黑", Font.BOLD, 26));
    boxH.add(topJL);

    outMoneyJL=new JLabel("请选择转出对象:");
    outMoneyJC = new JComboBox();

    outMoneyJC.addItem("---请选择---");
    outMoneyJC.addItem("账户");
    outMoneyJC.addItem("银行卡");
    outMoneyNumJL=new JLabel("请输入转出的卡号或手机号:");
    outMoneyJF =new JTextField();

    boxH1.add(outMoneyJL);
    boxH1.add(Box.createHorizontalStrut(10));
    boxH1.add(outMoneyJC);
    boxH1.add(Box.createHorizontalStrut(10));
    boxH1.add(outMoneyNumJL);
    boxH1.add(Box.createHorizontalStrut(10));
    boxH1.add(outMoneyJF);

    inMoneyJL=new JLabel("请选择转入对象:");
    inMoneyJC = new JComboBox();
    inMoneyJC.addItem("---请选择---");
    inMoneyJC.addItem("账户");
    inMoneyJC.addItem("银行卡");
    inMoneyNumJL=new JLabel("请输入转出的卡号或手机号:");
    inMoneyJF =new JTextField();
    boxH2.add(inMoneyJL);
    boxH2.add(Box.createHorizontalStrut(10));
    boxH2.add(inMoneyJC);
    boxH2.add(Box.createHorizontalStrut(10));
    boxH2.add(inMoneyNumJL);
    boxH2.add(Box.createHorizontalStrut(10));
    boxH2.add(inMoneyJF);


    moneyJL =new JLabel("请输入转帐金额:");
    moneyJF=new JTextField(20);
    moneyJF.setFont(new Font(null, Font.PLAIN, 20));
    boxH3.add(Box.createHorizontalStrut(30));
    boxH3.add(moneyJL);
    boxH3.add(Box.createHorizontalStrut(18));
    boxH3.add(moneyJF);
    boxH3.add(Box.createHorizontalStrut(30));

    stu =new JButton("确定");
    stu.setName("stu");
    stu.addMouseListener(this);
    boxH4.add(stu);

    boxV.add(boxH);
    boxV.add(Box.createVerticalStrut(40));
    boxV.add(boxH1);
    boxV.add(Box.createVerticalStrut(40));
    boxV.add(boxH2);
    boxV.add(Box.createVerticalStrut(40));
    boxV.add(boxH3);
    boxV.add(Box.createVerticalStrut(40));
    boxV.add(boxH4);
    boxV.add(Box.createVerticalStrut(80));

    this.add(boxV);

}
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
    }
    @Override
    public void mouseClicked(MouseEvent e) {
    String moneys = moneyJF.getText();
    String outCla=outMoneyJC.getSelectedItem().toString();
    String inCla=inMoneyJC.getSelectedItem().toString();
    String outNum=outMoneyJF.getText();
    String inNum=inMoneyJF.getText();
        if (moneys.equals("")){
            JOptionPane.showMessageDialog(null,"金额不能为空!");
            return;
        }
        else if("---请选择---".equals(outCla)||"---请选择---".equals(inCla)){
            JOptionPane.showMessageDialog(null,"请选择类型!");
            return;
        }
        else if (outNum.equals("")||inNum.equals("")){
            JOptionPane.showMessageDialog(null,"账户不能为空!");
        }

        try {
            double money = Double.parseDouble(moneys);
            if (money <= 0) {
                JOptionPane.showMessageDialog(null, "充值金额要大于0!");
                return;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "请输入数字!");
            return;
        }
        double money =Double.parseDouble(moneys);
        BanksController banksController =new BanksController();
        BanksController banksController1 =new BanksController();
        UserController userController=new UserController();
        boolean flag;
        boolean a = false,b=false;
        if (outCla.equals("银行卡")){
            a=banksController.chickNUm(outNum);
            if (inCla.equals("账户")){
                b=userController.chickNUm(inNum);
            }else if (inCla.equals("银行卡")){
                b=banksController.chickNUm(inNum);
            }
        }else if (outCla.equals("账户")){
            a=userController.chickNUm(outNum);
            if (inCla.equals("账户")){
                b=userController.chickNUm(inNum);
            }else if (inCla.equals("银行卡")){
                b=banksController.chickNUm(inNum);
            }
        }

        flag =a&&b;

//        boolean flag= banksController.moveMoney(banksNum,banksNum1,money);

        if(flag){
            //banksController.addMoney(banksNum,money);
            int f=0;
            if (outCla.equals("银行卡")){
                System.out.println("1银行卡减钱了");
                a=banksController.deleteMoney(outNum,money);
                if (inCla.equals("账户")&&a){
                    b=userController.addMoney(inNum,money);
                }else if (inCla.equals("银行卡")&&a){
                    System.out.println("二银行卡加钱了");
                    banksController1.addMoney(inNum,money);
                }else {
                    JOptionPane.showMessageDialog(null,"账户余额不足,转账失败!");
                    inMoneyJF.setText("");
                    outMoneyJF.setText("");
                    moneyJF.setText("");
                    f=1;
                }
            }else if (outCla.equals("账户")){
                a=userController.deleteMoney(outNum,money);
                if (inCla.equals("账户")&&a){
                    userController.addMoney(inNum,money);
                }else if (inCla.equals("银行卡")&&a){
                    System.out.println("2二银行卡加钱了");
                    banksController.addMoney(inNum,money);
                }else {
                    JOptionPane.showMessageDialog(null,"账户余额不足,转账失败!");
                    inMoneyJF.setText("");
                    outMoneyJF.setText("");
                    moneyJF.setText("");
                    f=1;
                }
            }if (f==0) {
                JOptionPane.showMessageDialog(null, "转账成功!");
                inMoneyJF.setText("");
                outMoneyJF.setText("");
                moneyJF.setText("");
                return;
            }
        }else {
            JOptionPane.showMessageDialog(null,"账户错误,转账失败!");
            inMoneyJF.setText("");
            outMoneyJF.setText("");
            moneyJF.setText("");
            return;
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

ShowBanksView

package com.baizhi.view;

import com.baizhi.entity.Banks;

import javax.swing.*;
import java.util.List;

public class ShowBanksView extends JPanel {
    List<Banks> List;
    public ShowBanksView(List<Banks> list){
        //System.out.println(list.size());
        JScrollPane js =new JScrollPane();
        Object[] clum = {"卡号","开户行","余额"};
        Object[][] data=new Object[list.size()][3];
        for (int i=0;i<list.size();i++){
            Banks b =list.get(i);
            data[i][0]=b.getBankNumber();
            data[i][1]=b.getBankName();
            data[i][2]=b.getMoney();
        }
        JTable jTable =new JTable(data,clum);
        js.setViewportView(jTable);
        this.add(js);


    }
}

ShowUserView

package com.baizhi.view;

import com.baizhi.entity.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.List;

public class ShowUserView extends JPanel {

    private JPanel top,bom;

    private JLabel telJL,pwdJL,nameJL,relnameJL,cardNumJL,emailJL,balJL;
    private JTextField telJF,nameJF,relnameJF,cardNumJF,emailJF,balJF;
    private JPasswordField pwdJF;
    public ShowUserView(User user, List<User> list){

        this.setLayout(new BorderLayout());
        top=new JPanel();
        JLabel topJL =new JLabel("个人信息展示");
        topJL.setFont(new Font("微软雅黑", Font.PLAIN, 26));
        top.add(topJL);
        this.add(top,BorderLayout.NORTH);

        //下边
        bom=new JPanel();

        bom.setLayout(new GridLayout(7,2,2,10));
        EmptyBorder job =new EmptyBorder(0,0,20,20);
        EmptyBorder fbo =new EmptyBorder(0,0,0,0);

        telJL =new JLabel("手机号",JLabel.LEFT);
        telJL .setIcon(new ImageIcon("img/phone_icon.png"));
        telJL.setBorder(job);

        telJF =new JTextField(20);
        telJF.setText(user.getTel());
        telJF.setBorder(fbo);
        bom.add(telJL);
        bom.add(telJF);

        pwdJL =new JLabel("密码",JLabel.LEFT);
        pwdJL .setIcon(new ImageIcon("img/password_icon.png"));
        pwdJL.setBorder(job);
        pwdJF = new JPasswordField(20);
        pwdJF.setText(user.getPwd());
        pwdJF.setBorder(fbo);
        bom.add(pwdJL);
        bom.add(pwdJF);

        nameJL =new JLabel("昵称",JLabel.LEFT);
        nameJL .setIcon(new ImageIcon("img/name_icon.png"));
        nameJL.setBorder(job);
        nameJF =new JTextField(20);
        nameJF.setText(user.getName());
        nameJF.setBorder(fbo);
        bom.add(nameJL);
        bom.add(nameJF);

        relnameJL =new JLabel("真实姓名",JLabel.LEFT);
        relnameJL .setIcon(new ImageIcon("img/username_icon.png"));
        relnameJL.setBorder(job);
        relnameJF =new JTextField(20);
        relnameJF.setText(user.getRelName());
        relnameJF.setBorder(fbo);
        bom.add(relnameJL);
        bom.add(relnameJF);

        cardNumJL =new JLabel("身份证号",JLabel.LEFT);
        cardNumJL .setIcon(new ImageIcon("img/idc_icon.png"));
        cardNumJL.setBorder(job);
        cardNumJF =new JTextField(20);
        cardNumJF.setText(user.getCardNum());
        cardNumJF.setBorder(fbo);
        bom.add(cardNumJL);
        bom.add(cardNumJF);

        emailJL =new JLabel("邮箱",JLabel.LEFT);
        emailJL .setIcon(new ImageIcon("img/msg_icon.png"));
        emailJL.setBorder(job);
        emailJF =new JTextField(20);
        emailJF.setText(user.getEmail());
        emailJF.setBorder(fbo);
        bom.add(emailJL);
        bom.add(emailJF);

        balJL =new JLabel("余额",JLabel.LEFT);
        balJL .setIcon(new ImageIcon("img/balance_icon.png"));
        balJL.setBorder(job);
        balJF =new JTextField(20);
        for (User user1:list){
            if (user1.getTel().equals(user.getTel())){
                balJF.setText(String.valueOf(user1.getMoney()));
            }
        }
        balJF.setBorder(fbo);
        bom.add(balJL);
        bom.add(balJF);

        this.add(bom,BorderLayout.CENTER);
    }

}

UpdatePwdView

package com.baizhi.view;

import com.baizhi.controller.UserController;
import com.baizhi.entity.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Objects;

public class UpdatePwdView extends JPanel implements MouseListener {

    ImageIcon icon;
    Image img;
    private User user;
    private Box boxV,boxH1,boxH2,boxH3,boxH,boxH4;
    private JButton relJB,subJB;
    private JLabel pwdJL,pwd1JL,topJL,pwd2JL;
    private JPasswordField pwdJP,pwd1JP,pwd2JP;

    public UpdatePwdView(User user){
        icon=new ImageIcon("img/bg.png");
        img=icon.getImage();
        this.user=user;
        boxV = Box.createVerticalBox();
        boxH= Box.createHorizontalBox();
        boxH1= Box.createHorizontalBox();
        boxH2= Box.createHorizontalBox();
        boxH3= Box.createHorizontalBox();
        boxH4=Box.createHorizontalBox();

        topJL=new JLabel("修改密码");
        topJL.setFont(new Font("微软雅黑", Font.BOLD, 26));
        boxH.add(topJL);

        pwd2JL=new JLabel("请输入原密码:");
        pwd2JP=new JPasswordField(20);
        pwd2JL.setFont(new Font(null, Font.PLAIN, 18));
        boxH4.add(Box.createHorizontalStrut(80));
        boxH4.add(pwd2JL);
        boxH4.add(pwd2JP);
        boxH4.add(Box.createHorizontalStrut(80));

        pwdJL=new JLabel("请输入新密码:");
        pwdJP=new JPasswordField(20);
        pwdJL.setFont(new Font(null, Font.PLAIN, 18));
        boxH1.add(Box.createHorizontalStrut(80));
        boxH1.add(pwdJL);
        boxH1.add(pwdJP);
        boxH1.add(Box.createHorizontalStrut(80));

        pwd1JL =new JLabel("再次输入密码:");
        pwd1JL.setFont(new Font(null, Font.PLAIN, 18));
        pwd1JP =new JPasswordField(20);
        boxH2.add(Box.createHorizontalStrut(80));
        boxH2.add(pwd1JL);
        boxH2.add(pwd1JP);
        boxH2.add(Box.createHorizontalStrut(80));

        subJB =new JButton("确定");
        subJB.setName("subJB");
        subJB.addMouseListener(this);
        relJB =new JButton("重置");
        relJB.setName("relJB");
        relJB.addMouseListener(this);
        boxH3.add(Box.createHorizontalStrut(40));
        boxH3.add(subJB);
        boxH3.add(Box.createHorizontalStrut(40));
        boxH3.add(relJB);


        boxV.add(boxH);
        boxV.add(Box.createVerticalStrut(50));
        boxV.add(boxH4);
        boxV.add(Box.createVerticalStrut(40));
        boxV.add(boxH1);
        boxV.add(Box.createVerticalStrut(40));
        boxV.add(boxH2);
        boxV.add(Box.createVerticalStrut(40));
        boxV.add(boxH3);
        boxV.add(Box.createVerticalStrut(100));

        this.add(boxV);

    }
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(img, 0, 0,this.getWidth(), this.getHeight(), this);
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        String str=e.getComponent().getName();
        String pwd2=new String(pwd2JP.getPassword());
        String pwd= new String(pwdJP.getPassword());
        String pwd1= new String(pwd1JP.getPassword());
        if(str.equals("subJB")) {
            if (pwd2.equals(user.getPwd())) {
                if (pwd.equals(pwd1)) {
                    if (pwd2.equals("")||pwd.equals("") || pwd1.equals("")) {
                        JOptionPane.showMessageDialog(null, "密码不能为空!");
                        pwdJP.setText("");
                        pwd1JP.setText("");
                        pwd2JP.setText("");
                    } else {
                        user.setPwd(pwd);
                        UserController userController =new UserController();
                        boolean flag =userController.updatePwd(user.getTel(),pwd2,pwd);
                        if (flag){
                            JOptionPane.showMessageDialog(null, "修改成功!");
                        }
                        pwdJP.setText("");
                        pwd1JP.setText("");
                        pwd2JP.setText("");
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "修改失败,两次密码不一致!");
                    pwdJP.setText("");
                    pwd1JP.setText("");
                    pwd2JP.setText("");
                }
            }else {
                JOptionPane.showMessageDialog(null, "修改失败,原密码错误!");
                pwdJP.setText("");
                pwd1JP.setText("");
                pwd2JP.setText("");
            }
        }
        if(str.equals("relJB")){
            pwdJP.setText("");
            pwd1JP.setText("");
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

UserLoginView

package com.baizhi.view;

import com.baizhi.controller.UserController;
import com.baizhi.entity.User;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class UserLoginView extends JFrame implements MouseListener {

    private JPanel jp;
    private JLabel top;
    private JPanel bom;
    private JLabel nameJL,pwdJL;
    private JTextField nameJF;
    private JPasswordField pwdJF;
    private JButton login,reg;

    public UserLoginView(){
        jp =new JPanel();
        jp.setLayout(new BorderLayout());

        top=new JLabel();
        ImageIcon icon =new ImageIcon("img/logo.png");
        icon.setImage(icon.getImage().getScaledInstance(300,50, Image.SCALE_DEFAULT));
        top.setIcon(icon);
        top.setBorder(new EmptyBorder(20,70,20,30));
        jp.add(top,BorderLayout.NORTH);
        bom =new JPanel();
        bom.setLayout(new GridLayout(3,2,20,20));
        bom.setBorder(new EmptyBorder(0,40,30,40));
       // jp.setLayout(new GridLayout(2,3,20,20));

        nameJL =new JLabel("手机号:",JLabel.RIGHT);
        nameJL.setIcon(new ImageIcon("img/username_icon.png"));
        nameJL.setBorder(new EmptyBorder(0,0,0,20));
        nameJF = new JTextField(20);
        pwdJL=new JLabel("密    码:",JLabel.RIGHT);
        pwdJL.setIcon(new ImageIcon("img/password_icon.png"));
        pwdJL.setBorder(new EmptyBorder(0,0,0,20));

        pwdJF=new JPasswordField(20);
        login =new JButton("登录");
        login.setName("login");
        login.addMouseListener(this);
        reg=new JButton("注册");
        reg.setName("reg");
        reg.addMouseListener(this);

        bom.add(nameJL);
        bom.add(nameJF);
        bom.add(pwdJL);
        bom.add(pwdJF);
        bom.add(login);
        bom.add(reg);
        jp.add(bom,BorderLayout.CENTER);
        this.add(jp);



        this.setSize(450,300);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setTitle("百知转账管理系统");
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    @Override
    public void mouseClicked(MouseEvent e) {
        String str =e.getComponent().getName();
        System.out.println(str);
        if(str.equals("login")){
            String tel =nameJF.getText();
            String pwd =new String(pwdJF.getPassword());
            if(tel.equals("")){
                JOptionPane.showConfirmDialog(null,"手机号不能为空");
            }else if(pwdJF.equals("")){
                JOptionPane.showConfirmDialog(null,"密码不能为空");
            }else{
                UserController userController =new UserController();
                User user=userController.userLog(tel,pwd);
                if (user==null){
                    JOptionPane.showMessageDialog(null,"登录失败!");

                }else {
                    System.out.println("成功进入主页面");
                    MainView mainView=new MainView(user);
                    dispose();
                }
            }
        }else {
            AddUserView ad=new AddUserView(this);
        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

UsersView

package com.baizhi.view;

import com.baizhi.entity.Banks;
import com.baizhi.entity.User;

import javax.swing.*;
import java.awt.event.MouseListener;
import java.util.List;

public class UsersView extends JPanel  {

//    String name, String cardNum, String tel, String pwd, String email, double money, String relName
    java.util.List<Banks> List;
    public UsersView(List<User> list){
        //System.out.println(list.size());
        JScrollPane js =new JScrollPane();
        Object[] clum = {"昵称","身份证号","电话号码","邮箱","余额","真实姓名"};
        Object[][] data=new Object[list.size()][6];
        for (int i=0;i<list.size();i++){
            User user =list.get(i);
            data[i][0]=user.getName();
            data[i][1]=user.getCardNum();
            data[i][2]=user.getTel();
            data[i][3]=user.getEmail();
            data[i][4]=user.getMoney();
            data[i][5]=user.getRelName();
        }
        JTable jTable =new JTable(data,clum);
        js.setViewportView(jTable);
        this.add(js);


    }
}

总结

拒绝白嫖,给个三连吧!

你可能感兴趣的:(Java学习,java)