Java-银行管理系统源代码

上传人:h****3 文档编号:231476061 上传时间:2023-09-04 格式:DOCX 页数:34 大小:23.90KB
返回 下载 相关 举报
Java-银行管理系统源代码_第1页
第1页 / 共34页
Java-银行管理系统源代码_第2页
第2页 / 共34页
Java-银行管理系统源代码_第3页
第3页 / 共34页
点击查看更多>>
资源描述
Java小型银行管理系统源代码(图形界面)accounts.javapackage Account;public class accounts protected int id;/银行账号protected String password;/用户密码protected String name;/用户型号protected String personId;/身份账号protected int accountType;/账号类型,0代表储蓄卡,1代表信用卡protected double balance;/账户余额。之所以定义为protected是让他的子类可以干脆用,不须要通过方法来赋值。protected double ceiling;public String getPassword()return password;public void setPassword(String password)this.password=password;public String getName()return name;public void setName(String name)this.name=name;public String getPersonId()return personId;public void setPersonId(String personId)this.personId=personId;public int getAccountType()return accountType;public void setAccountType(int accountType)this.accountType=accountType;public double getBalance()return balance;public void setBalance(double balance)this.balance=balance;public int getId()return id;public void setId(int id)this.id=id;public double getCeiling()return ceiling;public void setCeiling(double ceiling)this.ceiling=ceiling;/无参数构造方法public accounts()/构造方法public accounts(String password,String name,String personId,int accountType,double balance,double ceiling)super();this.password=password;this.name=name;this.personId=personId;this.accountType=accountType;this.balance=balance;this.ceiling=ceiling;/存款public void deposit(double money)balance+=money;/取款public void withdraw(double money)if(accountType=1)if(balance+ceiling)money)System.out.println(对不起,已超出您的信用额度!);elsebalance-=money;elseif(balancemoney)System.out.println(对不起,账户余额不足!);elsebalance-=money;DBoper.javapackage DB;import java.sql.*;import java.util.ArrayList;import Account.accounts;public class DBoper private Connection conn = null;private Statement st = null;private PreparedStatement pstmt = null;private ResultSet rs = null;private ArrayList result;/连接数据库public Connection getConnection()tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/localhost:3306/bankmanager?useUnicode=true&characterEncoding=utf8,root,xuewei);catch(Exception e)System.out.println(数据库连接失败);return conn;/修改 删除用户数据public boolean accountDataUpdate(String sql)conn=getConnection();trypstmt=conn.prepareStatement(sql);pstmt.executeUpdate();/System.out.println(数据更新胜利);conn.close();return true;catch(SQLException e)e.printStackTrace();/System.out.println(更新失败);return false;/依据id来修改记录public boolean dataupdateid(accounts user, int id) conn = getConnection();try String sql = update account set username=?,userpwd=?,personId=?,accountType=?,balance=?,ceiling=? where id=+ id;pstmt = conn.prepareStatement(sql);pstmt.setString(1, user.getName();pstmt.setString(2, user.getPassword();pstmt.setString(3, user.getPersonId();pstmt.setInt(4, user.getAccountType();pstmt.setDouble(5, user.getBalance();pstmt.setDouble(6, user.getCeiling();pstmt.executeUpdate();System.out.println(操作胜利);return true;catch (SQLException e) e.printStackTrace();System.out.println(操作失败);return false;/插入用户数据public boolean accountDataInsert(accounts account)conn=getConnection();trypstmt=conn.prepareStatement(insert into account (username,userpwd,personId,accountType,balance,ceiling) values (?,?,?,?,?,?);pstmt.setString(1, account.getName();pstmt.setString(2, account.getPassword();pstmt.setString(3, account.getPersonId();pstmt.setInt(4, account.getAccountType();pstmt.setDouble(5, account.getBalance();pstmt.setDouble(6, account.getCeiling();pstmt.executeUpdate();System.out.println(新用户数据插入胜利);conn.close();return true;catch(SQLException e)e.printStackTrace();System.out.println(插入失败);return false;/查询数据public ResultSet dataquery(String sql) conn = getConnection();try pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();catch (SQLException e) e.printStackTrace();System.out.println(检索失败);return rs;public ResultSet testlist() try String sql = select * from account where id =1001;pstmt = conn.prepareStatement(sql);System.out.println(sql);rs = pstmt.executeQuery(); catch (SQLException e) e.printStackTrace();System.out.println(检索失败);return rs;public ArrayList testt(int id) ArrayList list = new ArrayList();conn = getConnection();try String sql = select * from account where id= + id;pstmt = conn.prepareStatement(sql);rs = pstmt.executeQuery();while (rs.next() accounts user = new accounts();user.setName(rs.getString(username);user.setPassword(rs.getString(userpwd);user.setPersonId(rs.getString(personId);user.setAccountType(rs.getInt(accountType);user.setBalance(rs.getDouble(balance);user.setCeiling(rs.getDouble(ceiling);list.add(user);catch (SQLException e) e.printStackTrace();System.out.println(检索失败);return list;/依据卡号和密码验证用户是否存在public boolean verify(int id,String password)conn=getConnection();trypstmt=conn.prepareStatement(select * from account where id=? and userpwd=?);pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();if(rs.next()return true;elsereturn false;catch(SQLException e)e.printStackTrace();return false;/* * 登录验证 */public accounts verifyAccount(int id, String password) boolean flag = verify(id, password);if(flag)accounts account=queryByIDandPassword(id, password);return account;elseSystem.out.println(用户不存在!);return null;/依据卡号和密码查询信息public accounts queryByIDandPassword(int id,String password)conn=getConnection();trypstmt=conn.prepareStatement(select * from account where id=? and userpwd=?);pstmt.setInt(1, id);pstmt.setString(2, password);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()account.setId(rs.getInt(id);account.setName(rs.getString(username);account.setPassword(rs.getString(userpwd);account.setPersonId(rs.getString(personId);account.setAccountType(rs.getInt(accountType);account.setBalance(rs.getDouble(balance);account.setCeiling(rs.getDouble(ceiling);return account;catch(SQLException e)e.printStackTrace();return null;/依据卡号查询信息public accounts queryByID(int id)conn=getConnection();trypstmt=conn.prepareStatement(select * from account where id=?);pstmt.setInt(1, id);rs=pstmt.executeQuery();accounts account=new accounts();while(rs.next()account.setId(rs.getInt(id);account.setName(rs.getString(username);account.setPassword(rs.getString(userpwd);account.setPersonId(rs.getString(personId);account.setAccountType(rs.getInt(accountType);account.setBalance(rs.getDouble(balance);account.setCeiling(rs.getDouble(ceiling);return account;catch(SQLException e)e.printStackTrace();return null;public static void main(String args) / TODO Auto-generated method stubDBoper op=new DBoper();ArrayList list=op.testt(1001);for(int i=0;ilist.size();i+)accounts user=new accounts();user=list.get(i);System.out.println(user.getName();System.out.println(user.getPassword();System.out.println(user.getPersonId();System.out.println(user.getAccountType();System.out.println(user.getBalance();System.out.println(user.getCeiling();/图像界面文件夹DN_SYSTEMDefault.java /主界面package DN_SYSTEM;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class Default extends JFrame implements ActionListeneraccounts account=DN_ATM.client;DBoper db=new DBoper();private JFrame jf;private JButton btn0,btn1,btn2,btn3,btn4,btn5;private Container c;public void defaltDemo() /添加主界面卡片/DN_ATM.id;int id=DN_ATM.id;/account=db.queryByID(id);jf=new JFrame(DEFAULT);c=jf.getContentPane();c.setLayout(null);c.setBackground(new Color(119,119,253);JLabel lblwel = new JLabel(欢迎+account.getName()+用达能银行ATM系统);lblwel.setBounds(20, 15, 350, 30);c.add(lblwel);JLabel lblwel1 = new JLabel(请选择您须要的交易类型);lblwel1.setBounds(120, 45, 350, 30);c.add(lblwel1);btn1 = new JButton(取款服务);btn1.addActionListener(this);btn1.setBounds(70, 90, 100, 30);c.add(btn1);btn2=new JButton(存款服务);btn2.addActionListener(this);btn2.setBounds(210, 90, 100, 30);c.add(btn2);btn3 = new JButton(查询余额);btn3.addActionListener(this);btn3.setBounds(70, 150, 100, 30);c.add(btn3);btn4 = new JButton(转账服务);btn4.addActionListener(this);btn4.setBounds(210, 150, 100, 30);c.add(btn4);btn5 = new JButton(注销账户);btn5.addActionListener(this);btn5.setBounds(70, 210, 100, 30);c.add(btn5);btn0 = new JButton(退出操作);btn0.addActionListener(this);btn0.setBounds(210, 210, 100, 30);c.add(btn0);jf.setVisible(true);jf.setResizable(false); jf.setSize(400,300); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);/事务处理Overridepublic void actionPerformed(ActionEvent e)/取款服务if(e.getSource().equals(btn1)OutMoney outmoney=new OutMoney();outmoney.outMoney();jf.dispose();/存款服务if(e.getSource().equals(btn2)InMoney inmoney=new InMoney();inmoney.InMoney();jf.dispose();/查询余额if(e.getSource().equals(btn3)GetBalance getbalance=new GetBalance();getbalance.getBalance();jf.dispose();/转账服务if(e.getSource().equals(btn4)TransferAccounts tranfer=new TransferAccounts();tranfer.transferAccounts();jf.dispose();/注销账户if(e.getSource().equals(btn5)String sql=delete from account where id=+account.getId();boolean flag=db.accountDataUpdate(sql);if(flag)JOptionPane.showMessageDialog(this,注销胜利!);elseJOptionPane.showMessageDialog(this, 注销失败!);if(e.getSource().equals(btn0)System.exit(0);public static void main(String args) / TODO Auto-generated method stubDefault defaults=new Default();defaults.defaltDemo();DN_ATM.java/功能界面package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.AbstractButton;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import DB.DBoper;import Account.accounts;public class DN_ATM extends JFrame implements ActionListenerprivate JLabel lbljixu;private JButton btngetcard;private JButton btncard,btn010,btn_addAccount,btnsure,btnback;private JTextField txt1;private JPasswordField txt2;private Container container;private CardLayout Layout;private JLabel lblwrong;private JPanel panelfirst,panelmain;public static int id;static accounts client = null;public DN_ATM()super(达能银行);this.setSize(435, 350);this.setLocation(500,250);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/设置不行变更窗口大小this.setResizable(false);/布局public void setLayout()/用卡片布局Layout = new CardLayout();container = getContentPane();container.setLayout(Layout);/添加第一张卡片panelfirst = new JPanel(null);/设置卡片的背景颜色panelfirst.setBackground(new Color(119,119,253);lbljixu = new JLabel(请放入磁卡,然后接着操作);/设置卡片在Panel中的位置lbljixu.setBounds(140, 90, 350, 30);/为第一张卡片添加一个Labelpanelfirst.add(lbljixu);/为第一张卡片添加一个按钮btncard = new JButton(接着);btncard.setBounds(310, 180, 80, 30);/为按钮注册事务监听器btncard.addActionListener(this);/起先时设置按钮不行按btncard.setEnabled(false);panelfirst.add(btncard);/为第一张卡片添加一个按钮btngetcard = new JButton(取卡);btngetcard.setEnabled(false);btngetcard.setBounds(310, 220, 80, 30);btngetcard.addActionListener(this);panelfirst.add(btngetcard);/添加登录输入卡片panelmain = new JPanel(null);panelmain.setBackground(new Color(119,119,253);/添加登录输入卡号JLabel lblnumber = new JLabel(请输入您的银行卡卡号:);panelmain.add(lblnumber);lblnumber.setBounds(30, 30, 150, 30);/设置文本框为密码型txt1 = new JTextField(12);/文本框不行选中/txt1.enable(false);panelmain.add(txt1);txt1.setBounds(170, 30, 200, 30);JLabel lblpwd = new JLabel(请输入您的银行卡密码:);panelmain.add(lblpwd);lblpwd.setBounds(30, 80, 150, 30);/设置文本框为密码型txt2 = new JPasswordField(12);/文本框不行选中/txt2.enable(false);panelmain.add(txt2);/文本框的输入内容用*显示txt2.setEchoChar(*);txt2.setBounds(170, 80, 200, 30);/添加选择按钮btnsure = new JButton(确定);btnsure.addActionListener(this);panelmain.add(btnsure);btnsure.setBounds(70, 160, 80, 30);/添加重输按钮btn010 = new JButton(重输);btn010.addActionListener(this);panelmain.add(btn010);btn010.setBounds(175,160,80,30);btnback = new JButton(退出);btnback.addActionListener(this);panelmain.add(btnback);btnback.setBounds(280, 160, 80, 30);/开户btn_addAccount = new JButton(开户);btn_addAccount.setBounds(70, 220, 80, 30);btn_addAccount.addActionListener(this);panelmain.add(btn_addAccount);lblwrong = new JLabel(请留意爱护好您的密码!);panelmain.add(lblwrong);lblwrong.setBounds(180, 110, 200, 30);container.add(panelmain, main);/事务处理 SuppressWarnings(deprecation)Overridepublic void actionPerformed(ActionEvent e)DBoper db=new DBoper();if(e.getSource().equals(btn_addAccount)OpenAccount open=new OpenAccount();open.adduser();/磁卡插入后,验证银行登录卡号与密码if(e.getSource().equals(btnsure) client = db.verifyAccount(Integer.parseInt(txt1.getText(), txt2.getText();if(client!=null)Default defa=new Default();defa.defaltDemo();this.dispose();id=Integer.parseInt(txt1.getText();txt1.setText();txt2.setText();elselblwrong.setText(卡号或密码不正确,请重新输入!);txt1.setText();txt2.setText(); /重置输入卡号和密码if(e.getSource()=btn010) txt1.setText();txt2.setText(); lblwrong.setText(请留意爱护好您的密码!); /退出if(e.getSource().equals(btnback)System.exit(0);public static void main(String args) / TODO Auto-generated method stubDN_ATM ATM=new DN_ATM();ATM.setLayout();ATM.setVisible(true);GetBalance.java /查询余额package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class GetBalance extends JFrame implements ActionListenerprivate JFrame jf;private Container c;private JLabel lblremain1,lblremain;private JButton btnremain,btnremain1;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;/添加查询余额界面卡片public void getBalance()account=db.queryByID(id);jf=new JFrame(FIND DALANCE);c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);c.setBackground(new Color(119,119,253);lblremain1 = new JLabel(敬重的达能用户您好!);lblremain1.setBounds(90,70,350,30);c.add(lblremain1);lblremain = new JLabel(请点击接着操作查询余额:);lblremain.setBounds(90,110,350,30);c.add(lblremain);btnremain = new JButton(接着操作);btnremain.setBounds(95,150,90,30);btnremain.addActionListener(this);c.add(btnremain);btnremain1 = new JButton(退出操作); btnremain1.setBounds(200,150,90,30); btnremain1.addActionListener(this); c.add(btnremain1); jf.setVisible(true); jf.setSize(400,300); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent e)/查询余额if(e.getSource()=btnremain) lblremain1.setText(卡号:+account.getId()+ 用户名:+account.getName(); lblremain.setText(您的余额为+account.getBalance()+元,是否接着操作?); if(e.getSource()=btnremain1)Default defa=new Default();defa.defaltDemo();jf.dispose(); public static void main(String args) / TODO Auto-generated method stubGetBalance balance=new GetBalance();balance.getBalance();InMoney.java/存款package DN_SYSTEM;import java.awt.CardLayout;import java.awt.Color;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;import javax.swing.WindowConstants;import Account.accounts;import DB.DBoper;public class InMoney extends JFrame implements ActionListenerprivate JLabel lblsave,lblsave1;private JButton btnsave,btnsave2;private JTextField txt2;private double savemoney ;private double lastmoney;private boolean flag;private JFrame jf;private Container c;accounts account=new accounts();DBoper db=new DBoper();private int id=DN_ATM.id;public void InMoney()account=db.queryByID(id);jf=new JFrame(IN MONEY);c=jf.getContentPane();c.setLayout(null);jf.setResizable(false);/添加存款显示界面卡片c.setBackground(new Color(119,119,253);lblsave = new JLabel(请在存款口处放入存款);lblsave.setBounds(60,30,350,30);c.add(lblsave);lblsave1 = new JLabel(请留意:只接收100元或100元的整数倍存款);lblsave1.setBounds(90,110,350,30);c.add(lblsave1);txt2 = new JTextField(12);c.add(txt2);txt2.setBounds(95, 80, 200, 30);btnsave = new JButton(放入存款完毕);btnsave.setBounds(90,160,120,30);btnsave.addActionListener(this);c.add(btnsave);btnsave2 = new JButton(返回);btnsave2.setBounds(240,160,60,30);btnsave2.addActionListener(this);c.add(btns
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!