在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例文件解析和处理 → java 银行管理系统源码(入门级,文本型数据库)

java 银行管理系统源码(入门级,文本型数据库)

文件解析和处理

下载此实例
  • 开发语言:Java
  • 实例大小:0.08M
  • 下载次数:98
  • 浏览次数:1157
  • 发布时间:2018-06-10
  • 实例类别:文件解析和处理
  • 发 布 人:krispeng
  • 文件格式:.zip
  • 所需积分:20
 相关标签: bank system

实例介绍

【实例简介】

【实例截图】

from clipboard

from clipboard


from clipboard


from clipboard

from clipboard


如果运行时 菜单 或者 按钮 出现乱码 请在【 Run>>Edit Configrations>>VM Options】 增加 -Dfile.encoding=GB18030   ,具体配置见下图


from clipboard


【核心代码】


package banksystem.demo;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Arrays;

import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

public class MainFrame extends JFrame {

	private static final JDesktopPane DESKTOP_PANE = new JDesktopPane();
	private static int UserId = 0;
	private JFrame mainFrame;
	private JTable table;
	private AccountTableModel accountModel;

	public MainFrame() {
		super("这是主窗体");
		mainFrame = this;
		// 菜单设置
		JMenuBar menuBar = new JMenuBar();
		this.setJMenuBar(menuBar);
		JMenu reg = new JMenu("注册用户");
		JMenu edit = new JMenu("编辑用户");
		JMenu delete = new JMenu("删除用户");
		JMenu saveortake = new JMenu("存取款");
		JMenu bankstatement = new JMenu("查看流水");
		JMenuItem item1 = new JMenuItem("存入");
		JMenuItem item2 = new JMenuItem("取出");
		Button btn1 = new Button("存款");
		item1.add(btn1);
		Button btn2 = new Button("取款");
		item2.add(btn2);
		saveortake.add(item1);
		saveortake.add(item2);
		menuBar.add(reg);
		menuBar.add(edit);
		menuBar.add(delete);
		menuBar.add(saveortake);
		menuBar.add(bankstatement);
		accountModel = new AccountTableModel();
		table = new JTable(accountModel);
		JScrollPane jsp = new JScrollPane(table);
		jsp.setVisible(true);
		this.add(jsp);
		// this.getContentPane().add(DESKTOP_PANE);
		this.setTitle("银行管理系统");
		this.setSize(400, 200);
		this.setBounds((BankSystem.width - BankSystem.windowsWedth) / 2,
				(BankSystem.height - BankSystem.windowsHeight) / 2, BankSystem.windowsWedth - 150,
				BankSystem.windowsHeight - 150);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		reg.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// 注册界面布局
				JFrame frame = new JFrame();
				frame.setTitle("注册界面");
				frame.setSize(500, 200);
				frame.setBounds((BankSystem.width - BankSystem.windowsWedth) / 2,
						(BankSystem.height - BankSystem.windowsHeight) / 2, BankSystem.windowsWedth,
						BankSystem.windowsHeight);
				frame.setLayout(new BorderLayout());
				frame.setVisible(true);
				JPanel panelFirst = new JPanel();// 存放用户名密码
				JPanel panelSecond = new JPanel();// 存放按钮
				panelFirst.setLayout(new GridLayout(22, 22));
				JLabel userLabel = new JLabel("用户名");
				JLabel passLabel = new JLabel("密码");
				JLabel telLabel = new JLabel("电话");
				JTextField userText = new JTextField();
				JTextField passText = new JTextField();
				JTextField telText = new JTextField();
				panelFirst.add(userLabel);
				panelFirst.add(userText);
				panelFirst.add(passLabel);
				panelFirst.add(passText);
				panelFirst.add(telLabel);
				panelFirst.add(telText);
				panelSecond.setLayout(new FlowLayout());
				Button reg = new Button("注册");
				Button cancel = new Button("取消");
				panelSecond.add(reg);
				panelSecond.add(cancel);
				frame.add(panelSecond, BorderLayout.SOUTH);
				frame.add(panelFirst, BorderLayout.NORTH);
				/*
				 * JDialog jdlg = new JDialog(frame, "son", true);// 最后一个参数 true
				 * // 为模态 jdlg.setTitle("注册界面"); jdlg.setSize(500, 200);
				 * jdlg.setBounds((BankSystem.width - BankSystem.windowsWedth) /
				 * 2, (BankSystem.height - BankSystem.windowsHeight) / 2,
				 * BankSystem.windowsWedth, BankSystem.windowsHeight);
				 * jdlg.setLayout(new BorderLayout()); jdlg.setVisible(true);
				 */
				// 注册事件
				reg.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						String userName = userText.getText();
						String passWord = passText.getText();
						String telPhone = telText.getText();
						AccountModel newAccount = new AccountModel(BankSystem.accountLst.size()   1, userName, passWord,
								telPhone, 0.00, false);
						BankSystem.accountLst.add(newAccount);
						try {
							BankSystem.WriteFile(BankSystem.path, newAccount.toString(), true, false);
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						JOptionPane.showMessageDialog(null, "保存成功");
						accountModel.setDataSource(BankSystem.accountLst);
					}
				});
				cancel.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						frame.dispose();
					}
				});
			}

		});
		edit.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int rowId = table.getSelectedRow();
				if (rowId < 0) {
					JOptionPane.showMessageDialog(null, "请选择一行", "警告", JOptionPane.ERROR_MESSAGE);
					return;
				}
				// 注册界面布局
				JFrame frame = new JFrame();
				frame.setTitle("注册界面");
				frame.setSize(500, 200);
				frame.setBounds((BankSystem.width - BankSystem.windowsWedth) / 2,
						(BankSystem.height - BankSystem.windowsHeight) / 2, BankSystem.windowsWedth,
						BankSystem.windowsHeight);
				JPanel panelFirst = new JPanel();// 存放用户名密码
				JPanel panelSecond = new JPanel();// 存放按钮
				panelFirst.setLayout(new GridLayout(22, 22));
				JLabel userLabel = new JLabel("用户名");
				JLabel passLabel = new JLabel("密码");
				JLabel telLabel = new JLabel("电话");
				JTextField userText = new JTextField();
				JTextField passText = new JTextField();
				JTextField telText = new JTextField();
				panelFirst.add(userLabel);
				panelFirst.add(userText);
				panelFirst.add(passLabel);
				panelFirst.add(passText);
				panelFirst.add(telLabel);
				panelFirst.add(telText);
				panelSecond.setLayout(new FlowLayout());
				Button save = new Button("保存");
				Button cancel = new Button("取消");
				panelSecond.add(save);
				panelSecond.add(cancel);
				frame.setLayout(new BorderLayout());
				frame.add(panelSecond, BorderLayout.SOUTH);
				frame.add(panelFirst, BorderLayout.NORTH);
				frame.setVisible(true);
				userText.setText(table.getValueAt(rowId, 1).toString());
				passText.setText(table.getValueAt(rowId, 2).toString());
				telText.setText(table.getValueAt(rowId, 3).toString());
				UserId = Integer.parseInt(table.getValueAt(rowId, 0).toString());
				// 保存事件
				save.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						String userName = userText.getText();
						String passWord = passText.getText();
						String telPhone = telText.getText();
						AccountModel account = new AccountModel();
						for (int i = 0; i < BankSystem.accountLst.size(); i  ) {
							if (BankSystem.accountLst.get(i).getId() == UserId) {
								account = BankSystem.accountLst.get(i);
								BankSystem.accountLst.remove(account);
								break;
							}
						}
						account.setId(UserId);
						account.setUserName(userName);
						account.setPwd(passWord);
						account.setTelphone(telPhone);
						account.setBalance(account.getBalance());
						BankSystem.accountLst.add(account);
						boolean isAppend = false;
						boolean isNew = true;
						for (AccountModel tmpAcc : BankSystem.accountLst) {
							try {
								BankSystem.WriteFile(BankSystem.path, tmpAcc.toString(), isAppend, isNew);
								isAppend = true;
								isNew = false;
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						JOptionPane.showMessageDialog(null, "编辑成功");
						accountModel.setDataSource(BankSystem.accountLst);
					}
				});
				cancel.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseClicked(MouseEvent e) {
						frame.dispose();
					}
				});

			}
		});
		delete.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int rowId = table.getSelectedRow();
				if (rowId < 0) {
					JOptionPane.showMessageDialog(null, "请选择一行", "警告", JOptionPane.ERROR_MESSAGE);
					return;
				}
				UserId = Integer.parseInt(table.getValueAt(rowId, 0).toString());
				AccountModel account = new AccountModel();
				for (int i = 0; i < BankSystem.accountLst.size(); i  ) {
					if (BankSystem.accountLst.get(i).getId() == UserId) {
						account = BankSystem.accountLst.get(i);
						BankSystem.accountLst.remove(account);
						break;
					}
				}
				accountModel.setDataSource(BankSystem.accountLst);
				boolean isAppend = false;
				boolean isNew = true;
				for (AccountModel tmpAcc : BankSystem.accountLst) {
					try {
						BankSystem.WriteFile(BankSystem.path, tmpAcc.toString(), isAppend, isNew);
						isAppend = true;
						isNew = false;
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			}
		});
		btn1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int rowId = table.getSelectedRow();
				if (rowId < 0) {
					JOptionPane.showMessageDialog(null, "请选择一行", "警告", JOptionPane.WARNING_MESSAGE);
					return;
				}
				UserId = Integer.parseInt(table.getValueAt(rowId, 0).toString());
				String saveMoney = JOptionPane.showInputDialog("存入多少钱");
				Double money = Double.valueOf(saveMoney);
				AccountModel account = new AccountModel();
				for (int i = 0; i < BankSystem.accountLst.size(); i  ) {
					if (BankSystem.accountLst.get(i).getId() == UserId) {
						account = BankSystem.accountLst.get(i);
						BankSystem.accountLst.remove(account);
						break;
					}
				}
				account.setBalance(account.getBalance()   money);
				BankSystem.accountLst.add(account);
				accountModel.setDataSource(BankSystem.accountLst);
				boolean isAppend = false;
				boolean isNew = true;
				for (AccountModel tmpAcc : BankSystem.accountLst) {
					try {
						BankSystem.WriteFile(BankSystem.path, tmpAcc.toString(), isAppend, isNew);
						isAppend = true;
						isNew = false;
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				JOptionPane.showMessageDialog(null, " 保存成功");
				BankStatement.CreateBankStatement(
						new BankStatementModel(account.getId(), account.getUserName(), "存入", money));
			}
		});
		btn2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				int rowId = table.getSelectedRow();
				if (rowId < 0) {
					JOptionPane.showMessageDialog(null, "请选择一行", "警告", JOptionPane.WARNING_MESSAGE);
					return;
				}
				UserId = Integer.parseInt(table.getValueAt(rowId, 0).toString());
				String saveMoney = JOptionPane.showInputDialog("取出多少钱");
				Double money = Double.valueOf(saveMoney);
				AccountModel account = new AccountModel();
				for (int i = 0; i < BankSystem.accountLst.size(); i  ) {
					if (BankSystem.accountLst.get(i).getId() == UserId) {
						account = BankSystem.accountLst.get(i);
						BankSystem.accountLst.remove(account);
						break;
					}
				}
				if (account.getBalance() < money) {
					JOptionPane.showMessageDialog(null, "取出的金额比余额要多", "警告", JOptionPane.ERROR_MESSAGE);
					return;
				}
				account.setBalance(account.getBalance() - money);
				BankSystem.accountLst.add(account);
				accountModel.setDataSource(BankSystem.accountLst);
				boolean isAppend = false;
				boolean isNew = true;
				for (AccountModel tmpAcc : BankSystem.accountLst) {
					try {
						BankSystem.WriteFile(BankSystem.path, tmpAcc.toString(), isAppend, isNew);
						isAppend = true;
						isNew = false;
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				JOptionPane.showMessageDialog(null, "保存成功");
				BankStatement.CreateBankStatement(
						new BankStatementModel(account.getId(), account.getUserName(), "取出", money));
			}
		});

		bankstatement.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// BankStatementFrame frame=new BankStatementFrame();
				JFrame frame = new JFrame();
				BankStatementTableModel bankStatementTableModel = new BankStatementTableModel();
				JTable subTable = new JTable(bankStatementTableModel);
				JScrollPane jsp = new JScrollPane(subTable);
				jsp.setVisible(true);
				frame.add(jsp);
				// this.getContentPane().add(DESKTOP_PANE);
				frame.setTitle("银行管理系统");
				frame.setSize(400, 200);
				frame.setBounds((BankSystem.width - BankSystem.windowsWedth) / 2,
						(BankSystem.height - BankSystem.windowsHeight) / 2, BankSystem.windowsWedth - 150,
						BankSystem.windowsHeight - 150);
				frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				frame.setVisible(true);

			}
		});
	}
}


标签: bank system

实例下载地址

java 银行管理系统源码(入门级,文本型数据库)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 骚动的跳蚤 发表于: 2019-06-15 10:43 52
咋失效啦?

支持(0) 盖楼(回复)

第 2 楼 骚动的跳蚤 发表于: 2019-06-15 10:44 10
咋失效啦?能再发一遍吗

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有2条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警