java+gui+MySQL+简单mvc 模拟银行管理系统

又来水一下博客 !
项目的具体功能:实现了用户登录和管理员登录,管理员与登录实现对用户的增删改查的功能,用户登录实现存款、取款,转账,实时查看余额、查看转账流水的功能。
分层技术
在这里插入图片描述
主页面:

package org.vector.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import org.vector.been.Administrator;
import org.vector.been.User;
import org.vector.dao.AdministratorDao;
import org.vector.service.UserService;

@SuppressWarnings("serial")
public class HomePage extends JFrame{
	public void home() {
	JFrame frame = new JFrame();
	Container c = frame.getContentPane();
	JTextField account = new JTextField();
	JPasswordField password = new JPasswordField();
	JButton record = new JButton("登录");
	JButton register = new JButton("注册");
	JButton forget = new JButton("忘记/修改密码");
	User user = new User();
	// 窗口设置
		frame.setTitle("欢迎进入银行");
		int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
		frame.setBounds(width / 2 - 200, height / 2 - 220, 650, 650);
		c.setLayout(new BorderLayout());
		frame.setResizable(false);
		frame.setVisible(true);
		frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
			
		
		JPanel jpanel = new JPanel();
		jpanel.setBackground(Color.cyan);
		jpanel.setLayout(null);
		JLabel Bank = new JLabel("Bank");
		Bank.setFont(new Font("宋体", Font.PLAIN, 30));
		jpanel.add(Bank);
		Bank.setBounds(280, 10, 100, 30);
		c.add(jpanel, "North");
		
		// 创建两个单选按钮
        JRadioButton radioBtn01 = new JRadioButton("管理员");
        radioBtn01.setFont(new Font("宋体", Font.PLAIN, 20));
		radioBtn01.setBounds(180, 400, 100, 20);
        JRadioButton radioBtn02 = new JRadioButton("用   户");
        radioBtn02.setFont(new Font("宋体", Font.PLAIN, 20));
		radioBtn02.setBounds(400, 400, 100, 20);
        // 创建按钮组,把两个单选按钮添加到该组
        ButtonGroup btnGroup = new ButtonGroup();
        btnGroup.add(radioBtn01);
        btnGroup.add(radioBtn02);
        jpanel.add(radioBtn01);
        jpanel.add(radioBtn02);

		ImageIcon jpg = new ImageIcon("Image/1.jpg");
		jpg.setImage(jpg.getImage().getScaledInstance(200, 200, Image.SCALE_DEFAULT));
		JLabel a3 = new JLabel(jpg);
		a3.setBounds(240, 50, 200, 200);
		c.add(a3);
		
		JLabel a1 = new JLabel("账号:");
		a1.setFont(new Font("宋体", Font.PLAIN, 20));
		a1.setBounds(180, 280, 50, 20);
		JLabel a2 = new JLabel("密码:");
		a2.setFont(new Font("宋体", Font.PLAIN, 20));
		a2.setBounds(180, 360, 50, 20);
		jpanel.add(a1);
		jpanel.add(a2);
		account.setBounds(280, 275, 150, 30);
		account.setFont(new Font("宋体", Font.PLAIN, 18));

		password.setBounds(280, 355, 150, 30);
		password.setFont(new Font("宋体", Font.PLAIN, 18));

		jpanel.add(account);
		jpanel.add(password);
		c.add(jpanel, "Center");

		jpanel.add(register);
		jpanel.add(forget);
		register.setBounds(15, 550, 200, 40);
		register.setFont(new Font("宋体", Font.PLAIN, 15));
		forget.setBounds(425, 550, 200, 40);
		forget.setFont(new Font("宋体", Font.PLAIN, 15));
		c.add(jpanel);

		jpanel.add(record);
		record.setBounds(270, 450, 150, 75);
		record.setFont(new Font("宋体", Font.PLAIN, 20));
		c.add(jpanel);
		JLayeredPane jp = new JLayeredPane();
		register.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// 触发注册弹窗
				HomeRegist homeRegist = new HomeRegist();
				homeRegist.RegisterDialog();
				frame.setVisible(false);
			}

		});
		forget.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// 触发忘记密码弹窗
                HomeVerify honVerify = new HomeVerify();
                honVerify.ForgetDialog(user);
                frame.setVisible(false);
			}

		});
		record.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// 触发登录弹窗
				String str1 = account.getText();
				String str2 = password.getText();
				UserService userService = new UserService();
				AdministratorDao adminDao = new AdministratorDao();
				User user3 = userService.findNameAndCord(str1,str2);
				Administrator admin = adminDao.findNameAndCord(str1,str2);
				
					if(user3!=null && radioBtn02.isSelected()) {
						JOptionPane.showMessageDialog(null, "登录成功", "提示", JOptionPane.WARNING_MESSAGE);
						HomeMenu homeMenu = new HomeMenu();
						homeMenu.HomeMenu(user3);
						frame.setVisible(false);
					}
					else if(admin != null && radioBtn01.isSelected()){
						JOptionPane.showMessageDialog(null, "登录成功", "提示", JOptionPane.WARNING_MESSAGE);
						A_homeMain home = new A_homeMain();
						home.a_homeMain();
						frame.setVisible(false);
					}
					else {
						JOptionPane.showMessageDialog(null, "信息错误.", "提示", JOptionPane.ERROR_MESSAGE);
					}

				}
			}
           );
	}
}

在这里插入图片描述
注册页面:银行卡号后两位是随机的!

package org.vector.view;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import org.vector.been.User;
import org.vector.dao.UserDao;
import org.vector.service.UserService;

public class HomeRegist extends JFrame{

	User user = new User();

	public void RegisterDialog() {
		
		this.setTitle("注册");
		int width = Toolkit.getDefaultToolkit().getScreenSize().width;
		int height = Toolkit.getDefaultToolkit().getScreenSize().height;
		this.setBounds(width / 2 - 200, height / 2 - 180, 650, 500);
		JPanel c = (JPanel)this.getContentPane();
		c.setOpaque(false);
		this.setLayout(null);
		ImageIcon jpg = new ImageIcon("Image/4.jpg");
		jpg.setImage(jpg.getImage().getScaledInstance(650, 500, Image.SCALE_DEFAULT));
		JLabel s1 = new JLabel(jpg);
		s1.setBounds(0, 0, 650, 500);
		this.getLayeredPane().add(s1,new Integer(Integer.MIN_VALUE));
		JTextField name = new JTextField();

		name.setBounds(130, 55, 150, 30);
		name.setFont(new Font("宋体", Font.PLAIN, 18));

		JPasswordField password1 = new JPasswordField();

		password1.setBounds(130, 95, 150, 30);
		password1.setFont(new Font("宋体", Font.PLAIN, 18));
		JPasswordField password2 = new JPasswordField();

		password2.setFont(new Font("宋体", Font.PLAIN, 18));
		password2.setBounds(130, 140, 150, 30);
		JTextField IdCard = new JTextField();

		IdCard.setFont(new Font("宋体", Font.PLAIN, 18));
		IdCard.setBounds(130, 185, 150, 30);
		Random r = new Random();
		String str6 = "679855433"+r.nextInt(9)+r.nextInt(9);
		JLabel BankCard = new JLabel(str6);

		BankCard.setFont(new Font("宋体", Font.BOLD, 24));
		BankCard.setBounds(440, 55, 150, 30);
		BankCard.setForeground(Color.black);
		JPasswordField password3 = new JPasswordField();

		password3.setBounds(440, 95, 150, 30);
		password3.setFont(new Font("宋体", Font.PLAIN, 18));
		JTextField PhoneNumber = new JTextField();

		PhoneNumber.setFont(new Font("宋体", Font.PLAIN, 18));
		PhoneNumber.setBounds(440, 135, 150, 30);
		
		JButton m1 = new JButton("注册");
		m1.setBounds(10, 333, 60, 40);
		m1.setFont(new Font("宋体", Font.BOLD, 12));
		JButton m2 = new JButton("取消");
		m2.setBounds(572, 333, 60, 40);
		m2.setFont(new Font("宋体", Font.BOLD, 12));
		JRadioButton m3 = new JRadioButton("我已阅读服务条款");
		m3.setBounds(250, 275, 150, 40);
		m3.setFont(new Font("宋体", Font.BOLD, 12));
		JLabel a1 = new JLabel("姓名");
		a1.setForeground(Color.red);
		a1.setFont(new Font("宋体", Font.BOLD, 20));
		a1.setBounds(70, 30, 80, 80);
		JLabel a2 = new JLabel("密码");
		a2.setForeground(Color.red);
		a2.setFont(new Font("宋体", Font.BOLD, 20));
		a2.setBounds(70, 60, 100, 100);
		JLabel a3 = new JLabel("再次输入密码");
		a3.setForeground(Color.red);
		a3.setFont(new Font("宋体", Font.BOLD, 20));
		a3.setBounds(0, 105, 150, 100);
		JLabel a4 = new JLabel("身份证号");
		a4.setForeground(Color.red);
		a4.setFont(new Font("宋体", Font.BOLD, 20));
		a4.setBounds(41, 150, 100, 100);
		JLabel a5 = new JLabel("银行卡号");
		a5.setFont(new Font("宋体", Font.BOLD, 20));
		a5.setBounds(350, 20, 100, 100);
		JLabel a6 = new JLabel("支付密码");
		a6.setFont(new Font("宋体", Font.BOLD, 20));
		a6.setBounds(350, 60, 100, 100);
		JLabel a7 = new JLabel("  手机号");
		a7.setFont(new Font("宋体", Font.BOLD, 20));
		a7.setBounds(350, 100, 100, 100);
		JTextField a8 = new JTextField();
		a8.setBounds(150, 235, 310, 30);
		a8.setText("        <服务条款 > :  没啥说的,你就同意吧!");
		a8.setForeground(Color.RED);
		a8.setFont(new Font("宋体", Font.BOLD, 12));
		JLabel a9 = new JLabel("注册");
		a9.setFont(new Font("宋体", Font.BOLD, 24));
		a9.setBounds(294, 0, 100, 40);
		JLabel a10 = new JLabel("    账号");
		a10.setFont(new Font("宋体", Font.BOLD, 20));
		a10.setBounds(350, 140, 100, 100);
		JLabel a11 = new JLabel("(6~9位)");
		a11.setFont(new Font("宋体", Font.BOLD, 12));
		a11.setBounds(290, 95, 50, 20);

		JTextField account = new JTextField();
		account.setBounds(440, 175, 150, 30);
		account.setFont(new Font("宋体", Font.BOLD, 18));
		
		JLabel jLabel = new JLabel("请记好您的银行卡号!");
		jLabel.setFont(new Font("宋体", Font.BOLD, 30));
		jLabel.setBounds(200, 340, 400, 30);
		jLabel.setForeground(Color.red);
		this.add(jLabel);
		
		this.add(a1);
		this.add(a2);
		this.add(a3);
		this.add(a4);
		this.add(a5);
		this.add(a6);
		this.add(a7);
		this.add(a8);
		this.add(a9);
		this.add(name);
		this.add(password1);
		this.add(password2);
		this.add(password3);
		this.add(IdCard);
		this.add(BankCard);
		this.add(PhoneNumber);
		this.add(account);
		this.add(m1);
		this.add(m2);
		this.add(m3);
		this.add(a10);
		this.add(a11);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
			}
		});
		this.setResizable(false);
		this.setVisible(true);
		m1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				//点击注册
				String str1 = name.getText();
				String str2 = password1.getText();
				String str3 = password2.getText();
				String str4 = password3.getText();
				String str5 = IdCard.getText();
				String str7 = PhoneNumber.getText();
				String str8 = account.getText();
				user.setName(str1);
				user.setCord(str2);
				user.setPayment(str4);
				user.setId(str5);
				user.setNumber(str6);
				user.setPhone(str7);
				user.setAcount(str8);
				System.out.println(str4);
				System.out.println(str7);
				System.out.println(str8);
				
				UserService us = new UserService();
				int bl = us.Insert(user);
				User user2 = us.findIdAndNumberAndAcount(str5, str6, str8);
				if(str2.equals(str3)) {
					if(m3.isSelected()) {
						if(user2 == null && bl != 0) {
							JOptionPane.showMessageDialog(null, "注册成功","提示",JOptionPane.ERROR_MESSAGE);
							HomePage homePage = new HomePage();
							homePage.home();
						}
						else
							JOptionPane.showMessageDialog(null, "注册失败","提示",JOptionPane.WARNING_MESSAGE);
					}
					else
						JOptionPane.showMessageDialog(null, "请同意条款","提示",JOptionPane.WARNING_MESSAGE);
				}
				else 
					JOptionPane.showMessageDialog(null, "密码错误","提示",JOptionPane.WARNING_MESSAGE);
				
			}
		});
		m2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// 取消按钮
				HomePage homePage = new HomePage();
				homePage.home();
				setVisible(false);
			}

		});
	}	
}

在这里插入图片描述
忘记密码:
在这里插入图片描述
登陆后的页面:
在这里插入图片描述

页面布局纯手工搭建,代码很好理解,所有的技术都是一样的套路,适合初学者使用,其中有不好的地方请见谅。需要源代码的私聊或者加QQ:3316127206

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值