Java小项目-银行用户管理系统

文章目录

  • 前言
  • 一. 功能
  • 二. 代码
    • 银行卡数据
    • 转账流水数据
    • 用户数据
    • BanksController
    • UserController
    • BanksDao
    • RecordDao
    • UserDao
    • Banks
    • Record
    • User
    • BanksService 接口
    • UserService接口
    • BanksServiceImpl
    • UsersServiceImpl
    • AppStar 测试类
    • ConnectMsql (JDBC连接Mysql数据库)
    • AddBanksMoneyView
    • AddBanksView
    • AddUsersMoneyView
    • AddUserView
    • MainView
    • MoveMoneyView
    • ShowBanksView
    • ShowMoveMoney
    • ShowUserView
    • UpdatePwdView
    • UserLoginView
    • UsersView


前言

银行用户管理系统是由我的另一篇博客项目 Java实训项目——网银管理系统改编而来。 与之不同的是,这个小项目新增了 转账流水功能, 并且运用了 集合,JavaSpring,Mysql数据库和JDBC。 虽然大同小异,但亦有可取之处。

一. 功能

  1. 登陆

  2. 注册

  3. 首页

  4. 个人信息显示

  5. 修改密码

  6. 添加银行卡

  7. 银行卡查看

  8. 充值

  9. 提现

  10. 转账

  11. 用户管理

  12. 转账流水

把用户信息,银行卡信息和转账流水(包括充值,提现和转账)都存入数据库之中,在根据功能合理的使用这些数据。
详细的功能介绍在上一篇项目博客中已经介绍过了 ——网银管理系统。

二. 代码

Java小项目-银行用户管理系统_第1张图片

银行卡数据

Java小项目-银行用户管理系统_第2张图片

转账流水数据

Java小项目-银行用户管理系统_第3张图片

用户数据

Java小项目-银行用户管理系统_第4张图片

BanksController

package com.vector.controller;

import com.vector.entity.Banks;
import com.vector.service.BanksService;
import com.vector.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.vector.controller;

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

import java.sql.SQLException;
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);}
}

BanksDao

package com.vector.dao;

import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.units.ConnectMsql;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class BanksDao {
    public boolean write(List<Banks> list){
        try {
        	String delsql = "delete from banks where bankNum = ?";
			String sql = "insert into banks(bankNum,money,bankName,tel) values(?,?,?,?)";
			Connection connection = ConnectMsql.getConnectMsql();
			PreparedStatement ad = connection.prepareStatement(sql);
			PreparedStatement del = connection.prepareStatement(delsql);
			int f=0;
			for(Banks user:list) {
				del.setString(1, user.getBankNumber());
				del.executeUpdate();
				ad.setString(1, user.getBankNumber());
				ad.setDouble(2, user.getMoney());
				ad.setString(3, user.getBankName());
				ad.setString(4, user.getTel());
				int i = ad.executeUpdate();
				if(i<0) {
				 System.out.println("添加失败!");
				 f++;
			     return false;
				}
			}
			if (f==0) {
				System.out.println("添加成功");
			}
        } catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			ConnectMsql.closeConnection();
		}
		return true;
    }
    
    
    public List<Banks> read(){
    	List<Banks> list=new ArrayList<>();
		Connection connection = ConnectMsql.getConnectMsql();
		Statement stmt;
		try {
			stmt = connection.createStatement();
			ResultSet rs = stmt.executeQuery("select * from banks");
		while (rs.next()) {
			Banks bank =new Banks(rs.getString("bankNum"), rs.getDouble("money"), rs.getString("bankName"), rs.getString("tel"));
			list.add(bank);
		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			ConnectMsql.closeConnection();
		}
		 return list;
	}

    
}

RecordDao

package com.vector.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import com.vector.entity.Banks;
import com.vector.entity.Record;
import com.vector.units.ConnectMsql;

public class RecordDao {
	public boolean write(List<Record> list) {
		LocalDateTime dateTime = LocalDateTime.now(); 
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
		String dataString=new String(dateTime.format(formatter));
		  try {  	
			    String delsql = "delete from movemoney where id = ?";
				String sql = "insert into movemoney(outuser,inuser,money,date,id) values(?,?,?,?,?)";
				Connection connection = ConnectMsql.getConnectMsql();
				PreparedStatement ad = connection.prepareStatement(sql);
				PreparedStatement del = connection.prepareStatement(delsql);
				int f=0,k=1;
				for(Record record:list) {
					del.setInt(1, record.getId());
					del.executeUpdate();
					ad.setString(1, record.getOutuser());
					ad.setString(2, record.getInuser());
					ad.setDouble(3, record.getMoney());
					ad.setString(4,dataString);
					ad.setInt(5,k);
					int i = ad.executeUpdate();
					k++;
					if(i<0) {
					 System.out.println("添加失败!");
					 f++;
				     return false;
					}
				}
				if (f==0) {
					System.out.println("添加成功");
				}
	        } catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				ConnectMsql.closeConnection();
			}
			return true;
	    }
	    
	    
	    public List<Record> read(){
	    	List<Record> list=new ArrayList<>();
			Connection connection = ConnectMsql.getConnectMsql();
			Statement stmt;
			try {
				stmt = connection.createStatement();
				ResultSet rs = stmt.executeQuery("select * from movemoney");
			while (rs.next()) {
				Record record =new Record(rs.getString("outuser"), rs.getString("inuser"),rs.getDouble("money"), rs.getString("date"),rs.getInt("id"));
				list.add(record);
			}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				ConnectMsql.closeConnection();
			}
			 return list;
		}

}

UserDao

package com.vector.dao;

import java.util.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.sound.midi.Soundbank;

import com.vector.entity.User;
import com.vector.units.ConnectMsql;

public class UserDao {
	public boolean write(List<User> list) {
		try {
			String delsql = "delete from user where tel = ?";
			String sql = "insert into user(name,cardNum,tel,pwd,email,money,relName) values(?,?,?,?,?,?,?)";
			Connection connection = ConnectMsql.getConnectMsql();
			PreparedStatement ad = connection.prepareStatement(sql);
			PreparedStatement del = connection.prepareStatement(delsql);
			int f=0;
			for(User user:list) {
				del.setString(1, user.getTel());
				del.executeUpdate();
				//System.out.println("这是密码"+user.getPwd());
				ad.setString(1, user.getName());
				ad.setString(2, user.getCardNum());
				ad.setString(3, user.getTel());
				ad.setString(4, user.getPwd());
				ad.setString(5, user.getEmail());
				ad.setDouble(6, user.getMoney());
				ad.setString(7, user.getRelName());
				int i = ad.executeUpdate();
				if(i<0) {
				 System.out.println("添加失败!");
				 f++;
			     return false;
				}
			}
			if (f==0) {
				System.out.println("添加成功");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			ConnectMsql.closeConnection();
		}
		return true;

	}
	public List<User> read() {
		List<User> list=new ArrayList<>();
		Connection connection = ConnectMsql.getConnectMsql();
		Statement stmt;
		try {
			stmt = connection.createStatement();
		ResultSet rs = stmt.executeQuery("select * from user");
		while (rs.next()) {
			User user=new User(rs.getString("name"), rs.getString("cardNum"), rs.getString("tel"),rs.getString("pwd"),rs.getString("email"), rs.getDouble("money"), rs.getString("relName"));
			list.add(user);
		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			ConnectMsql.closeConnection();
		}
		 return list;
	}
}

Banks

package com.vector.entity;

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

public class Banks  {
    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 + '\'' +
                '}';
    }
}

Record

package com.vector.entity;

public class Record {
	private String outuser;
	private String inuser;
	private double money;
	private String date;
	private int id;
	public String getOutuser() {
		return outuser;
	}
	public void setOutuser(String outuser) {
		this.outuser = outuser;
	}
	public String getInuser() {
		return inuser;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public void setInuser(String inuser) {
		this.inuser = inuser;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	
	
	public Record(String outuser, String inuser, double money, String date, int id) {
		super();
		this.outuser = outuser;
		this.inuser = inuser;
		this.money = money;
		this.date = date;
		this.id = id;
	}
	@Override
	public String toString() {
		return "Record [outuser=" + outuser + ", inuser=" + inuser + ", money=" + money + ", date=" + date + "]";
	}
}

User

package com.vector.entity;

import java.io.Serializable;

public class User  {
    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 + '\'' +
                '}';
    }
}


BanksService 接口

package com.vector.service;

import com.vector.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.vector.service;

import com.vector.entity.Banks;
import com.vector.entity.User;

import java.sql.SQLException;
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);
}

BanksServiceImpl

package com.vector.service.impl;

import com.vector.dao.BanksDao;
import com.vector.dao.BanksDao;
import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.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.vector.service.impl;

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

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersServiceImpl implements UserService {

    private UserDao dao =new UserDao();
    private RecordDao dao1 =new RecordDao();

    @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();
        for(User user2 : list) {
        	if(user.getTel().equals(user2.getTel())){
        		return false;
        	}
        }
        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;
    }

   
    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); 
                // System.out.println(user.getPwd());
                 return dao.write(list);
            }
        }
		return false;
	    
       
    }

      
    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);
            }
       }
		return false;

       
    }

    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);
    }

  
    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;
    }
    
    
    public boolean addRecord(String out,String in,Double money) {
    	List<Record> list =dao1.read();
    	Record record =new Record(out, in, money, "0",0);
    	list.add(record);
    	return dao1.write(list);
    }
    public List<Record> showRecords() {
    	List<Record>list =dao1.read();
		return list;
	}

}

AppStar 测试类

package com.vector.test;

import com.vector.view.UserLoginView;

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

ConnectMsql (JDBC连接Mysql数据库)

package com.vector.units;

import java.sql.*;

public class ConnectMsql {
	public static Connection connect;

	public static Connection getConnectMsql() {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			// Class.forName("org.gjt.mm.mysql.Driver");
			 //System.out.println("成功加载Mysql驱动程序!");
		} catch (Exception e) {
			System.out.print("加载Mysql驱动程序时出错!");
			e.printStackTrace();
		}
		try {
			connect = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/BankManagementSystem?&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true",
					"root", "zpx");

			//System.out.println("成功连接Mysql服务器!");
			Statement stmt = connect.createStatement();
		} catch (Exception e) {
			System.out.print("获取连接错误!");
			e.printStackTrace();
		}
		return connect;
	}

	public static void closeConnection() {
		if (connect != null) {
			try {
				connect.close();
				// System.out.println("数据库连接关闭");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

AddBanksMoneyView

package com.vector.view;

import com.vector.controller.BanksController;
import com.vector.controller.UserController;
import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.service.impl.UsersServiceImpl;

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,"提现成功");
            UsersServiceImpl usersServiceImpl =new UsersServiceImpl();
            if (usersServiceImpl.addRecord(user.getTel(),banksNum, money)) {
				System.out.println("存取记录成功!");
			}
            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.vector.view;

import com.vector.controller.BanksController;
import com.vector.dao.BanksDao;
import com.vector.entity.Banks;
import com.vector.entity.User;


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.vector.view;

import com.vector.controller.BanksController;
import com.vector.controller.UserController;
import com.vector.entity.Banks;
import com.vector.entity.User;
import com.vector.service.impl.UsersServiceImpl;

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,"充值成功");
                    UsersServiceImpl usersServiceImpl =new UsersServiceImpl();
                    if (usersServiceImpl.addRecord(banksNum,user.getTel(), money)) {
        				System.out.println("存取记录成功!");
        			}
                    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.vector.view;

import com.vector.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.vector.view;

import com.vector.controller.BanksController;
import com.vector.controller.UserController;
import com.vector.entity.Banks;
import com.vector.entity.Record;
import com.vector.entity.User;
import com.vector.service.UserService;
import com.vector.service.impl.UsersServiceImpl;

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,showMoveMoneyJB;


    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_zhiti.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);
        
        showMoveMoneyJB =new JButton("转账流水");
        showMoveMoneyJB.setForeground(Color.BLUE);
        showMoveMoneyJB.setName("showMoveMoneyJB");
        showMoveMoneyJB.setBorder(jb);
        showMoveMoneyJB.addMouseListener(this);
        leftJP.add(showMoveMoneyJB);

        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/bj_vector.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.setTitle("银行账户管理系统");
        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;
            case "showMoveMoneyJB":
            	UsersServiceImpl usersServiceImpl =new UsersServiceImpl();
            	List<Record> list2 =usersServiceImpl.showRecords();
            	ShowMoveMoney showMoveMoney =new ShowMoveMoney(list2);
            	updateView(showMoveMoney);
            	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.vector.view;

import com.vector.controller.BanksController;
import com.vector.controller.UserController;
import com.vector.entity.Banks;
import com.vector.service.impl.UsersServiceImpl;

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("");
                UsersServiceImpl usersServiceImpl =new UsersServiceImpl();
                if (usersServiceImpl.addRecord(outNum, inNum, money)) {
					System.out.println("存取记录成功!");
				}
                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.vector.view;

import com.vector.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);


    }
}

ShowMoveMoney

package com.vector.view;

import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import com.vector.entity.Banks;
import com.vector.entity.Record;

public class ShowMoveMoney extends JPanel{
	    public ShowMoveMoney(List<Record> list){
	        //System.out.println(list.size());
	        JScrollPane js =new JScrollPane();
	        Object[] clum = {"转出用户","转入用户","金额","日期"};
	        Object[][] data=new Object[list.size()][4];
	        for (int i=0;i<list.size();i++){
	            Record b =list.get(i);
	            data[i][0]=b.getOutuser();
	            data[i][1]=b.getInuser();
	            data[i][2]=b.getMoney();
	            data[i][3]=b.getDate();
	        }
	        JTable jTable =new JTable(data,clum);
	        js.setViewportView(jTable);
	        this.add(js);
	    }

}

ShowUserView

package com.vector.view;



import com.vector.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.vector.view;

import com.vector.controller.UserController;
import com.vector.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.vector.view;
import com.vector.controller.*;
import com.vector.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_zhibi.png");
        icon.setImage(icon.getImage().getScaledInstance(300,80, 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.setIconImage(new ImageIcon("img/bj_vector.jpg").getImage());
        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.vector.view;

import com.vector.entity.*;
import com.vector.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)