一个简单的java语言编写的银行账户管理系统

结合了 GUI 界面 与 IO流操作

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;public class background extends JFrame {JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel; //面板public background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);       //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));      //把标签添加到分层面板的最底层}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Check {/*** 在登录时, 验证账号密码是否正确*/public boolean  check1(String countname,String pwd) throws IOException{File file=new File("Message.txt");   //创建文件类if(!file.exists()||file.isDirectory()) //判断文件是否存在//throw new FileNotFoundException();file.createNewFile();BufferedReader br=new BufferedReader(new FileReader(file)); //创建读入缓冲流,按行读入String temp=null;   // StringBuffer sb=new StringBuffer();   temp=br.readLine();   //先读取一行while(temp!=null){String sbstring = temp.toString();   //转化为stringint n = sbstring.length();            //测字符串长度String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证int k=0;for (int i=0; i<5; i++)message[i]="";//我们在写入账户时用~分割, 所以我们利用~在分割开来for (int i=0; i<n; i++){if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (countname.equals(message[2])&&pwd.equals(message[3]))//比较账户密码是否相等return true;temp=br.readLine();  //读取下一行}return false;}//在注册时 验证账号是否存在public boolean  check2(String countname) throws IOException{File file=new File("Message.txt");   //创建文件类if(!file.exists()||file.isDirectory()) //判断文件是否存在file.createNewFile();BufferedReader br=new BufferedReader(new FileReader(file)); //创建读入缓冲流,按行读入String temp=null;   // StringBuffer sb=new StringBuffer();   temp=br.readLine();   //先读取一行while(temp!=null){String sbstring = temp.toString();   //转化为stringint n = sbstring.length();            //测字符串长度String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证int k=0;for (int i=0; i<5; i++)message[i]="";for (int i=0; i<n; i++){if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (countname.equals(message[2]))return true;temp=br.readLine();}return false;}//在挂失是 找回密码需要验证, 姓名,身份证号,和账户是否与注册时保持一致public String  check3(String name, String userid,String countname) throws IOException{File file=new File("Message.txt");   //创建文件类if(!file.exists()||file.isDirectory()) //判断文件是否存在file.createNewFile();BufferedReader br=new BufferedReader(new FileReader(file)); //创建读入缓冲流,按行读入String temp=null;   // StringBuffer sb=new StringBuffer();   temp=br.readLine();   //先读取一行while(temp!=null){String sbstring = temp.toString();   //转化为stringint n = sbstring.length();            //测字符串长度String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证int k=0;for (int i=0; i<5; i++)message[i]="";for (int i=0; i<n; i++){if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (name.equals(message[0])&&userid.equals(message[1])&&countname.equals(message[2]))return message[3];temp=br.readLine();}return null;}//判断金额是否合法public boolean checkmoney(String money){for(int i=0; i<money.length(); i++){if (money.charAt(i)<'0'||money.charAt(i)>'9')return false;}  return true;}//验证用户名和密码是否为中文public boolean checkcountname(String countname){Pattern p = Pattern.compile("[\u4e00-\u9fa5]");Matcher m = p.matcher(countname);if (m.find()) {return true;}return false;}//验证姓名是否为中文public boolean checkname(String name){int n = 0;for(int i = 0; i < name.length(); i++) {n = (int)name.charAt(i);if(!(19968 <= n && n <40869)) {return false;}}return true;}
}

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;import javax.swing.ImageIcon;
import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Detail extends JFrame implements ActionListener{JButton jb1;JTextArea jta1;JScrollPane jsp1;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);        //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));      //把标签添加到分层面板的最底层}public Detail(String countname) throws IOException {Background();//设置布局this.setTitle("明细");this.setLayout(null);this.setSize(380, 350); jb1 = new JButton("确定");jta1 = new JTextArea();jb1.addActionListener(this);jta1.setFont(new   java.awt.Font("Dialog",   0,   15)); //设置字体为字形, 不加粗,15号字体jb1.setBounds(150, 280, 62, 28);jta1.setBounds(20, 20, 340, 240);this.add(jb1);this.add(jta1);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口         this.setVisible(true);  //设置可见this.setResizable(false); //设置不可拉伸大小File file = new File(countname+".txt");try {FileReader fr = new FileReader(file);BufferedReader br=new BufferedReader(fr);String temp ;String all = "";all = "                 交易时间                    交易金额  明细\r\n";while(br.ready()) {temp = br.readLine();all += temp + "\n";                }jta1.setText(all);fr.close();} catch (FileNotFoundException e) {e.printStackTrace();}}@Overridepublic void actionPerformed(ActionEvent e) {if(e.getActionCommand()=="确定") {dispose();}}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;/*** 本类实现 对取钱操作的实现, 主要思路 实现对用户金额的修改* 但在输入金额时 要判断 金额的大小 是否能够取出  且不能出现负数* * * **/
public class DrawMoney extends JFrame implements ActionListener{private NewButton button;String countname;JButton jb1, jb2, jb3;  //按钮JLabel jlb1, jlb2, jlb3; //标签JTextArea jta1,jta2;JButton jb100,jb200,jb500,jb1000;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);     //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public DrawMoney(String countname) {this.countname = countname;Background();jb1 = new NewButton("确定");jb2 = new NewButton("重置");jb100 = new NewButton("100");jb200 = new NewButton("200");jb500 = new NewButton("500");jb1000 = new NewButton("1000");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jb100.addActionListener(this);jb200.addActionListener(this);jb500.addActionListener(this);jb1000.addActionListener(this);jlb1 = new JLabel("请输入取出金额:");  //添加标签//创建文本框jta1 = new JTextArea();jta2 = new JTextArea();//设置布局this.setTitle("取钱");this.setLayout(null);this.setSize(310, 310); //存入标签和文本框jlb1.setBounds(90, 20, 200, 20);jta1.setBounds(100, 50, 150, 50);jta1.setFont(new java.awt.Font("Dialog",   0,   15));//确定和重置按钮jb1.setBounds(100, 120, 62, 28);jb2.setBounds(190, 120, 62, 28);//显示结果文本框//jlb1.setBounds(5, 20, 200, 20);jta2.setBounds(100, 160, 150, 50);jta2.setFont(new   java.awt.Font("Dialog",   1,   15));//jta2.setText("您的余额为:\n ");//金额jb100.setBounds(7, 40, 70, 30);jb200.setBounds(7, 90, 70, 30);jb500.setBounds(7, 140, 70, 30);jb1000.setBounds(7, 190, 70, 30);this.add(jlb1);this.add(jta1);this.add(jb1);this.add(jb2);this.add(jta2);this.add(jb100);this.add(jb200);this.add(jb500);this.add(jb1000);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);    //设置不可拉伸大小}//清空账号和密码框private void clear() {jta1.setText("");    //设置为空jta2.setText("");  }@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="100"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="200"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="500"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="1000"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="确定"){try {drawmoney();   //将存入金额传入判断是否合法} catch (IOException e1) {e1.printStackTrace();}}else if (e.getActionCommand()=="重置"){clear();}new Menu();}private void drawmoney() throws IOException {if (jta1.getText().isEmpty()){JOptionPane.showMessageDialog(null, "金额为空,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if(new Check().checkmoney(jta1.getText())){String nowmoney = new UserMessage().updatemoney(countname,-Integer.parseInt(jta1.getText()));if (!nowmoney.equals("负数")){//记录明细File file=new File(countname+".txt");FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加 StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(new java.util.Date()+"    "+"-"+jta1.getText()+"  取款   "+"\r\n");out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();          //关闭//jta2.setText("您的余额为:\n "+nowmoney+" 数科币");jta1.setText("");}else {JOptionPane.showMessageDialog(null, "余额不足请重新输入:","消息提示",JOptionPane.WARNING_MESSAGE);clear();}}else {JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}}}
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.*;
/*** 此类时对用户信息查询的编写,  我们将查询出用户的姓名身份证号和余额* * **/
public class Inquiry extends JFrame implements ActionListener{JLabel jlb1, jlb2, jlb3;  //标签JTextField jtf1,jtf2,jtf3;   //文本框JPasswordField jpf; //密码框JPanel jp1,jp2,jp3;      //面板JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);     //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Inquiry(String countname) throws IOException {Background();//标签信息jlb1 = new JLabel("        姓名");jlb2 = new JLabel("身份证号");jlb3 = new JLabel("        余额");jtf1 = new JTextField(13);jtf2 = new JTextField(13);jtf3 = new JTextField(13);jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jp1.add(jlb1);jp1.add(jtf1);jp2.add(jlb2);jp2.add(jtf2);jp3.add(jlb3);jp3.add(jtf3);//设置布局this.setTitle("查询");this.setLayout(null);   //采用空布局jp1.setBounds(-10, 40, 300 ,50);   //-别问我为什么-10 因为 界面好看一点啊jp2.setBounds(-10, 110, 300 ,50);jp3.setBounds(-10, 180, 300 ,50);//将JPane加入JFrame中  this.add(jp1);  this.add(jp2);  this.add(jp3); this.setSize(300, 300);   //设置窗体大小this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);  //设置不可拉伸大小String []message = new UserMessage().read(countname);//将姓名的第一个字变为*message[0] ="*"+message[0].substring(1,message[0].length());//将身份证号第6到12位变成*message[1] =message[1].substring(0,6)+"*******"+message[1].substring(13,message[1].length());jtf1.setText(message[0]);jtf2.setText(message[1]);jtf3.setText(message[4]+" 数科币");}@Overridepublic void actionPerformed(ActionEvent arg0) {}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;public class Land extends JFrame implements ActionListener{NewButton button;JButton jb1, jb2, jb3,jb4;JTextField jtf;   //文本框JLabel jlb1, jlb2, jlb3,jlb4,jlb5,jlb6,jlb7;//标签JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景04.jpg");label = new JLabel(background);      //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Land(){Background();jb1 = new NewButton("登录");jb2 = new NewButton("注册");jb3 = new NewButton("找回密码");jb4 = new NewButton("退出");jlb1 = new JLabel("数");jlb1.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb2 = new JLabel("科");jlb2.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb3 = new JLabel("银");jlb3.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb4 = new JLabel("行");jlb4.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb5 = new JLabel("欢");jlb5.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb6= new JLabel("迎");jlb6.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jlb7 = new JLabel("您");jlb7.setFont(new   java.awt.Font("Dialog",   1,   31)); //设置字体类型, 是否加粗,字号jb1.addActionListener(this);   //事件监听jb2.addActionListener(this);jb3.addActionListener(this);jb4.addActionListener(this);this.setTitle("数科银行管理系统");  //设置窗体标题this.setSize(400, 450);        //设置窗体大小this.setLocation(400, 200);     //设置位置this.setLayout(null);         //设置布局,不采用布局jb1.setBounds( 30,50,90,60);   jb2.setBounds( 30,130,90,60);jb3.setBounds(30,210,90,60);jb4.setBounds( 30,290,90,60);jlb1.setBounds(200, 50, 50, 50);jlb2.setBounds(200, 130, 50, 50);jlb3.setBounds(200, 210, 50, 50);jlb4.setBounds(200, 290, 50, 50);jlb5.setBounds(260, 90, 50, 50);jlb6.setBounds(260, 170, 50, 50);jlb7.setBounds(260, 250, 50, 50);this.add(jb1);   //加入窗体this.add(jb2);this.add(jb3);this.add(jb4);this.add(jlb1);this.add(jlb2);this.add(jlb3);this.add(jlb4);this.add(jlb5);this.add(jlb6);this.add(jlb7);this.setDefaultCloseOperation(EXIT_ON_CLOSE);  //设置可关闭this.setVisible(true);  //设置可见this.setResizable(false);    //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="登录") {new Login();          }else if (e.getActionCommand()=="注册"){new Register();  //跳转开户界面}else if (e.getActionCommand()=="找回密码"){new ReportLose();  }else if (e.getActionCommand()=="退出"){JOptionPane.showMessageDialog(null, "谢谢使用!","消息提示",JOptionPane.CLOSED_OPTION);System.exit(0);}}  //按钮}
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.*;
/*** 此类为用户登录界面* * **/
public class Login extends JFrame implements ActionListener{JButton jb1, jb2, jb3;  //按钮JPanel jp1,jp2,jp3, jp4;        //面板JTextField jtf;   //文本框JLabel jlb1, jlb2, jlb3; //标签JPasswordField jpf; //密码框private NewButton button;public Login() {jb1 = new NewButton("登录");jb2 = new NewButton("重置");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jp1 = new JPanel();  //创建面板jp2 = new JPanel();jp3 = new JPanel();jlb1 = new JLabel("用户名");  //添加标签jlb2 = new JLabel("  密  码");jtf = new JTextField(10);   //创建文本框和密码框jpf = new JPasswordField(10);//加入面板中jp1.add(jlb1);jp1.add(jtf);jp2.add(jlb2);jp2.add(jpf);jp3.add(jb1);jp3.add(jb2);//将JPane加入JFrame中  this.add(jp1);  this.add(jp2);  this.add(jp3);  //设置布局this.setTitle("用户登录");this.setLayout(new GridLayout(3,1));this.setSize(300, 200);   //设置窗体大小this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);   //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="登录"){try {login();} catch (HeadlessException | IOException e1) {e1.printStackTrace();}}else if(e.getActionCommand()=="重置")  {  clear();  }}//清空账号和密码框private void clear() {jtf.setText("");    //设置为空jpf.setText("");  }//验证登录信息,并做处理public void login() throws HeadlessException, IOException{//判断账户名和密码是否包含中文if (new Check().checkcountname(jtf.getText())||new Check().checkcountname(jpf.getText())){JOptionPane.showMessageDialog(null, "用户名或密码存在中文,不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty()){JOptionPane.showMessageDialog(null, "账号密码为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if (jtf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "账号为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if (jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "密码为空,请输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if (new Check().check1(jtf.getText(),jpf.getText())){JOptionPane.showMessageDialog(null,"登录成功!","提示消息",JOptionPane.WARNING_MESSAGE);dispose();  //使文原窗体消失new Menu(jtf.getText());//登陆成功后  弹出菜单}    else{JOptionPane.showMessageDialog(null, "账号密码错误请重新输入!","消息提示",JOptionPane.ERROR_MESSAGE);clear();  //调用清除函数}            }}
import java.io.IOException;public class Main {public static void main(String[] args) throws IOException {new Land();//登录}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.*;
/*** * * Menu是一个 菜单类,也是最为底层的一个类* 提供各个功能的按钮* * 此类未使用布局, 所以使用坐标固定了各个标签和按钮的位置**/public class Menu extends JFrame implements ActionListener{JButton jb1, jb2, jb3,jb4,jb5,jb6,jb7, jb8;  //创建按钮JLabel jlb1, jlb2, jlb3,jlb4;   //标签private NewButton button;String countname;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景04.jpg");label = new JLabel(background);      //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Menu() {}public Menu(String countname ) {Background();this.countname = countname;jb1 = new NewButton("余额");jb1.setFont(new   java.awt.Font("楷体",   1,   30));jb2 = new NewButton("存款");jb2.setFont(new   java.awt.Font("楷体",   1,   30));jb3 = new NewButton("取款");jb3.setFont(new   java.awt.Font("楷体",   1,   30));jb4 = new NewButton("转账");jb4.setFont(new   java.awt.Font("楷体",   1,   30));jb5 = new NewButton("改密");jb5.setFont(new   java.awt.Font("楷体",   1,   30));jb6 = new NewButton("明细");jb6.setFont(new   java.awt.Font("楷体",   1,   30));jb7 = new NewButton("退卡");jb7.setFont(new   java.awt.Font("楷体",   1,   30));jb8 = new NewButton("打印");jb8.setFont(new   java.awt.Font("楷体",   1,   30));jlb1 = new JLabel("数");jlb1.setFont(new   java.awt.Font("Dialog",   1,   80)); //设置字体类型, 是否加粗,字号jlb2 = new JLabel("科");jlb2.setFont(new   java.awt.Font("Dialog",   1,   80));jlb3 = new JLabel("银");jlb3.setFont(new   java.awt.Font("Dialog",   1,   80));jlb4 = new JLabel("行");jlb4.setFont(new   java.awt.Font("Dialog",   1,   80));jb1.addActionListener(this);   //事件监听jb2.addActionListener(this);jb3.addActionListener(this);jb4.addActionListener(this);jb5.addActionListener(this);jb6.addActionListener(this);jb7.addActionListener(this);jb8.addActionListener(this);this.setTitle("银行管理系统");  //设置窗体标题this.setSize(900, 600);      //设置窗体大小this.setLocation(400, 200);     //设置位置this.setLayout(null);         //设置布局,不采用布局//设置按钮的位置和大小jb1.setBounds( 20,50,200,60);   jb2.setBounds( 20,200,200,60);jb3.setBounds( 20,350,200,60);jb4.setBounds( 680,50,200,60);jb5.setBounds( 680,200,200,60);jb6.setBounds( 680,350,200,60);jb7.setBounds(500,470,200,60);jb8.setBounds(200,470,200,60);//设置标签的位置和大小
//      jlb1.setBounds(150,120,150,50);
//      jlb2.setBounds(190,160,150,50);
//      jlb3.setBounds(150,250,150,50);jlb1.setBounds(430, 10, 150, 150);jlb2.setBounds(430, 120, 150, 150);jlb3.setBounds(430, 230, 150, 150);jlb4.setBounds(430, 340, 150, 150);this.add(jb1);   //加入窗体this.add(jb2);this.add(jb3);this.add(jb4);this.add(jb5);this.add(jb6);this.add(jb7);this.add(jb8);this.add(jlb1);this.add(jlb2);this.add(jlb3);this.add(jlb4);this.setDefaultCloseOperation(EXIT_ON_CLOSE);  //设置可关闭this.setVisible(true);  //设置可见this.setResizable(false);    //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="余额"){//String order = e.getActionCommand();try {new Inquiry(countname);} catch (IOException e1) {e1.printStackTrace();} }else if (e.getActionCommand()=="存款"){new SaveMoney(countname);}else if (e.getActionCommand()=="取款"){new DrawMoney(countname);}else if (e.getActionCommand()=="转账"){new Transfer(countname);}else if (e.getActionCommand()=="改密"){new Modify(countname);}else if (e.getActionCommand()=="明细"){try {new Detail(countname);} catch (IOException e1) {e1.printStackTrace();}  }else if (e.getActionCommand()=="打印"){try {new Print(countname);} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}  }else if (e.getActionCommand()=="退卡"){JOptionPane.showMessageDialog(null, "谢谢使用!","消息提示",JOptionPane.CLOSED_OPTION);dispose();}}}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.ImageIcon;
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;/*** 实现改密操作* * **/
public class Modify extends JFrame implements ActionListener{JButton jb1, jb2, jb3;  //按钮JPanel jp1,jp2,jp3, jp4;       //面板JPasswordField jtf1,jtf2;   //文本框JLabel jlb1, jlb2, jlb3; //标签String name = "123";   //账号密码String pwd = "123"; String countname;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);       //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Modify(String countname) {this.countname = countname;Background();jb1 = new JButton("确定");jb2 = new JButton("重置");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jp1 = new JPanel();  //创建面板jp2 = new JPanel();jp3 = new JPanel();jlb1 = new JLabel("    新密码");  //添加标签jlb2 = new JLabel("重复密码");jtf1 = new JPasswordField(10);   //创建文本框jtf2 = new JPasswordField(10);//加入面板中jp1.add(jlb1);jp1.add(jtf1);jp2.add(jlb2);jp2.add(jtf2);jp3.add(jb1);jp3.add(jb2);//将JPane加入JFrame中  this.add(jp1);  this.add(jp2);  this.add(jp3);  //设置布局this.setTitle("用户登录");this.setLayout(new GridLayout(3,1));  //利用网格布局this.setSize(300, 200);   //设置窗体大小this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);  //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getActionCommand()=="确定"){try {modify();  //进行信息核对} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}  }else if (e.getActionCommand()=="重置"){clear();   //清楚信息}}private void modify() throws IOException {// TODO Auto-generated method stubif (jtf1.getText().isEmpty()||jtf2.getText().isEmpty())  //判断信息是否为空{JOptionPane.showMessageDialog(null, "信息未填写完成!","消息提示",JOptionPane.WARNING_MESSAGE);}else if (jtf1.getText().equals(jtf2.getText())){new UserMessage().updatepwd(countname, jtf1.getText());   //调用UserMessage的updatepwd函数更新密码JOptionPane.showMessageDialog(null, "修改成功!","消息提示",JOptionPane.WARNING_MESSAGE);dispose();}else {JOptionPane.showMessageDialog(null, "2次密码不一致,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);clear();}}//清空密码框private void clear() {// TODO Auto-generated method stubjtf1.setText("");    //设置为空jtf2.setText("");  }}
/*NewButton类,继承JButton类重写用于绘制按钮形状的函数*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class NewButton extends JButton
{private String s;public NewButton(String s)    //传递图片引用{super(s);setContentAreaFilled(false);}protected void paintComponent(Graphics g)    //绘制按钮内容{g.setColor(new Color(255,255,224));g.fillRoundRect(0,0,getSize().width-1,getSize().height-1,15,15);        //绘制一个圆角矩形getSize()为获取组件的大小//g.drawImage(img, 0,0,50, 40, null);      //除了形状外还可以为按钮绘制一个图片来美化按钮  super.paintComponent(g);    //使用父类函数绘制一个焦点框}protected void paintBorder(Graphics g)   //绘制按钮边框{g.drawRoundRect(0,0,getSize().width-1,getSize().height-1,15,15);}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;import javax.swing.ImageIcon;
import javax.swing.JButton;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;public class Print extends JFrame implements ActionListener{JButton jb1;JTextArea jta1;String all;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);      //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));      //把标签添加到分层面板的最底层}   public Print (String countname) throws IOException  {Background();this.setTitle("打印");this.setLayout(null);this.setSize(380, 350); jb1 = new JButton("点击打印");jta1 = new JTextArea();jb1.addActionListener(this);jta1.setFont(new   java.awt.Font("Dialog",   0,   15)); //设置字体为字形, 不加粗,15号字体jb1.setBounds(150, 280, 100, 28);jta1.setBounds(20, 20, 340, 240);this.add(jb1);this.add(jta1);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口            this.setVisible(true);  //设置可见this.setResizable(false); //设置不可拉伸大小File file01 = new File(countname+".txt");File file02 = new File("Message.txt");try {FileReader fr01 = new FileReader(file01);BufferedReader br01=new BufferedReader(fr01);FileReader fr02 = new FileReader(file02);BufferedReader br02=new BufferedReader(fr02);String message[] = new String [5];String name = "";String idnumber = "";String nowmoney = "";String temp02;while(br02.ready()) {temp02 = br02.readLine();message = temp02.split("~");if(message[2].equals(countname)) {          //寻找用户名name = message[0];idnumber = message[1];nowmoney = message[4];break;}}String temp01;String all = "";all = "                            数科银行                           \r\n";all +="姓名: "+name+"\r\n";all +="用户名: "+countname+"\r\n";all +="身份证号: "+idnumber+"\r\n";all += "                 交易时间                    交易金额  明细\r\n";while(br01.ready()) {temp01 = br01.readLine();all += temp01 + "\n";}all += "\n";all +="余额: "+nowmoney+" 数科币";this.all = all;jta1.setText(all);fr01.close();fr02.close();} catch (FileNotFoundException e) {e.printStackTrace();}}@Overridepublic void actionPerformed(ActionEvent e) {if(e.getActionCommand()=="点击打印") {                                  //System.out.println("-------------------------------------------------");System.out.println(all);System.out.println("-------------------------------------------------");}}}
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.*;/*** 此类完成对开户页面的编写, 用户需填写 姓名,身份证号, 账户,密码,开户金额信息* * 并且会进行验证操作, 如姓名是否合法(中文), 身份证号是否合法等等* * **/
public class Register extends JFrame implements ActionListener{JButton jb1, jb2;  //按钮JLabel jlb1, jlb2, jlb3,jlb4,jlb5, jlb6;  //标签JTextField jtf1,jtf2,jtf3,jtf4, jtf5;   //文本框JPasswordField jpf; //密码框JPanel jp1,jp2,jp3, jp4,jp5,jp6,jp7;      //面板JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);     //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Register() {Background();//按钮jb1 = new JButton("确定");jb2 = new JButton("重置");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);//标签信息jlb1 = new JLabel("        姓名");jlb2 = new JLabel("身份证号");jlb3 = new JLabel("        账号");jlb4 = new JLabel("        密码");jlb6 = new JLabel("注册信息");jlb5 = new JLabel("开户金额");jlb6.setFont(new   java.awt.Font("Dialog",   1,   20));   //设置字体类型,加粗,大小为20//文本信息jtf1 = new JTextField(13);jtf2 = new JTextField(13);jtf3 = new JTextField(13);jtf4 = new JTextField(13);jtf5 = new JTextField(13);jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jp4 = new JPanel();jp5 = new JPanel();jp6 = new JPanel();jp7 = new JPanel();//将对应信息加入面板中jp1.add(jlb1);jp1.add(jtf1);jp2.add(jlb2);jp2.add(jtf2);jp3.add(jlb3);jp3.add(jtf3);jp4.add(jlb4);jp4.add(jtf4);jp5.add(jlb5);jp5.add(jtf5);jp6.add(jb1);jp6.add(jb2);jp7.add(jlb6);//将JPane加入JFrame中  this.add(jp7);  //先加入提示语this.add(jp1);  this.add(jp2);  this.add(jp3); this.add(jp4);this.add(jp5);this.add(jp6);//设置布局this.setTitle("注册信息");this.setLayout(new GridLayout(7, 1));this.setSize(350, 350);   //设置窗体大小this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);    //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getActionCommand()=="确定"){try {register();} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}else if (e.getActionCommand()=="重置"){clear();}}//验证注册信息,并做处理public void register() throws IOException{//判断信息是否补全if (jtf1.getText().isEmpty()||jtf2.getText().isEmpty()||jtf3.getText().isEmpty()||jtf4.getText().isEmpty()||jtf5.getText().isEmpty()){JOptionPane.showMessageDialog(null, "信息有空缺,请补全!","消息提示",JOptionPane.WARNING_MESSAGE);}//判断身份证号是否为18位else if (jtf2.getText().length()!=18){JOptionPane.showMessageDialog(null, "非法身份证号,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}//判断金额是否合法else if (!new Check().checkmoney(jtf5.getText())){  JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}//判断姓名是否为全中文else if (!new Check().checkname(jtf1.getText())){JOptionPane.showMessageDialog(null, "姓名不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}//判断账户名和密码是否包含中文else if (new Check().checkcountname(jtf3.getText())||new Check().checkcountname(jtf4.getText())){JOptionPane.showMessageDialog(null, "用户名或密码存在中文,不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}//满足要求else if (!jtf1.getText().isEmpty()&&!jtf2.getText().isEmpty()&&!jtf3.getText().isEmpty()&&!jtf4.getText().isEmpty()&&!jtf5.getText().isEmpty()){//注册成功, 打包为信息数组传递给UserMessage进行更新操作String []message = new String[5]; message[0] = jtf1.getText();   //获取输入的文本信息message[1] = jtf2.getText();message[2] = jtf3.getText();message[3] = jtf4.getText();message[4] = jtf5.getText();if (!new Check().check2(message[2]))   //调用Check的check方法检测用户是否存在, 如果不存在执行{new UserMessage().write(message);   //调用UserMseeage的write方法进行写操作, 将信息格式化存入JOptionPane.showMessageDialog(null,"注册成功!","提示消息",JOptionPane.WARNING_MESSAGE);dispose();  //使窗口消失}else {JOptionPane.showMessageDialog(null,"账号已存在,请重新输入!","提示消息",JOptionPane.WARNING_MESSAGE);//dispose();}}}//清空账号和密码框private void clear() {// TODO Auto-generated method stubjtf1.setText("");    //设置为空jtf2.setText("");  jtf3.setText("");  jtf4.setText("");  jtf5.setText("");  }}
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.ImageIcon;
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.JTextArea;
import javax.swing.JTextField;/*** * * **此类是对挂失模块的编写,用户利用身份证号和姓名, 进行对户名下的账号进行找回密码操作*/
public class ReportLose extends JFrame implements ActionListener{JButton jb1, jb2, jb3;  //按钮JPanel jp1,jp2,jp3, jp4;       //面板JTextField jtf1,jtf2,jtf3,jtf4;   //文本框JLabel jlb1, jlb2, jlb3; //标签JTextArea jta;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);       //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public ReportLose() {Background();jb1 = new JButton("确定");jb2 = new JButton("重置");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jp1 = new JPanel();  //创建面板jp2 = new JPanel();jp3 = new JPanel();jp4 = new JPanel();jlb1 = new JLabel("        姓名");  //添加标签jlb2 = new JLabel("身份证号");jlb3 = new JLabel("        账号");jtf1 = new JTextField(13); //创建文本框jtf2 = new JTextField(13);jtf3 = new JTextField(13);//创建文本框jta = new JTextArea();//加入面板中jp1.add(jlb1);jp1.add(jtf1);jp2.add(jlb2);jp2.add(jtf2);jp3.add(jlb3);jp3.add(jtf3);jp4.add(jb1);jp4.add(jb2);//设置布局this.setTitle("找回密码");this.setLayout(new GridLayout(6,1));  //采用网格布局 6,1this.setSize(400, 350); //this.setLocation(400, 200);//将JPane加入JFrame中  this.add(jp1);  this.add(jp2);  this.add(jp3);  this.add(jp4);this.add(jta);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);  //设置不可拉伸大小}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="确定"){try {ok();} catch (HeadlessException e1) {e1.printStackTrace();} catch (IOException e1) {e1.printStackTrace();}}else if(e.getActionCommand()=="重置")  {  clear();  }}//private void ok() throws HeadlessException, IOException {//信息有空缺if (jtf1.getText().isEmpty()||jtf2.getText().isEmpty()||jtf3.getText().isEmpty()){JOptionPane.showMessageDialog(null, "信息有空缺,请补全!","消息提示",JOptionPane.WARNING_MESSAGE);}//判断身份证号是否为18位else if (jtf2.getText().length()!=18){JOptionPane.showMessageDialog(null, "非法身份证号,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else{String []message = new String[3]; message[0] = jtf1.getText();message[1] = jtf2.getText();message[2] = jtf3.getText();if (new Check().check2(message[2]))   //调用Check的check方法检测用户是否存在, 如果存在{String nowpwd = new Check().check3(message[0],message[1],message[2]);//判断姓名,身份证号, 用户名,是否匹配if (nowpwd!=null){JOptionPane.showMessageDialog(null,"请点击确定查看!","提示消息",JOptionPane.WARNING_MESSAGE);jta.setText("您的密码为:"+nowpwd+"  ,请妥善保存!");}else{JOptionPane.showMessageDialog(null,"用户信息和该账号不匹配,请核对!","提示消息",JOptionPane.WARNING_MESSAGE);}}else {JOptionPane.showMessageDialog(null,"账号不存在,请核对账户信息!","提示消息",JOptionPane.WARNING_MESSAGE);//dispose();}}}//清空账号和密码框private void clear() {jtf1.setText("");    //设置为空jtf2.setText("");jtf3.setText("");  }}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;/*** 本类实现对存钱的操作  注意金额的处理* * **/
public class SaveMoney extends JFrame implements ActionListener{String countname;JButton jb1, jb2, jb3;  //按钮JLabel jlb1, jlb2, jlb3; //标签JTextArea jta1,jta2;private NewButton button;JButton jb100,jb200,jb500,jb1000;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);     //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));      //把标签添加到分层面板的最底层}public SaveMoney(String countname) {Background();this.countname = countname;jb1 = new NewButton("确定");jb2 = new NewButton("重置");jb100 = new NewButton("100");jb200 = new NewButton("200");jb500 = new NewButton("500");jb1000 = new NewButton("1000");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jb100.addActionListener(this);jb200.addActionListener(this);jb500.addActionListener(this);jb1000.addActionListener(this);jlb1 = new JLabel("请输入存入金额:");  //添加标签//创建文本框jta1 = new JTextArea();jta2 = new JTextArea();//设置布局this.setTitle("存钱");this.setLayout(null);this.setSize(310, 310); //存入标签和文本框jlb1.setBounds(90, 20, 200, 20);jta1.setBounds(100, 50, 150, 50);jta1.setFont(new   java.awt.Font("Dialog",   0,   15)); //设置字体为字形, 不加粗,15号字体//确定和重置按钮jb1.setBounds(100, 120, 62, 28);jb2.setBounds(190, 120, 62, 28);jb100.setBounds(7, 40, 70, 30);jb200.setBounds(7, 90, 70, 30);jb500.setBounds(7, 140, 70, 30);jb1000.setBounds(7, 190, 70, 30);//显示结果文本框//jlb1.setBounds(5, 20, 200, 20);jta2.setBounds(100, 160, 150, 50);jta2.setFont(new   java.awt.Font("Dialog",   1,   15));//jta2.setText("您的余额为:\n ");this.add(jlb1);this.add(jta1);this.add(jb1);this.add(jb2);this.add(jta2);this.add(jb100);this.add(jb200);this.add(jb500);this.add(jb1000);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);   //设置不可拉伸大小}//清空账号和密码框private void clear() {jta1.setText("");    //设置为空jta2.setText("");  }@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="100"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="200"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="500"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="1000"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="确定"){try {savemoney();   //将存入金额传入判断是否合法} catch (IOException e1) {e1.printStackTrace();}}else if (e.getActionCommand()=="重置"){clear();}new Menu();}private void savemoney() throws IOException {if (jta1.getText().isEmpty()){JOptionPane.showMessageDialog(null, "金额为空,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if(new Check().checkmoney(jta1.getText()))  //验证金额是否合法{//将账户和金额传入, 进行存储String nowmoney = new UserMessage().updatemoney(countname,Integer.parseInt(jta1.getText()));if (!nowmoney.equals("负数")){//记录明细File file=new File(countname+".txt");FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加 StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(new java.util.Date()+"    "+"+"+jta1.getText()+"  存款   "+"\r\n");out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();           //关闭//文本显示                  jta2.setText("您的余额为:\n "+nowmoney+" 数科币");jta1.setText("");}}else {JOptionPane.showMessageDialog(null, "存入金额不合法!","消息提示",JOptionPane.WARNING_MESSAGE);}}//写入账户明细public void writeDetail(String countname) throws IOException {if(new Check().check2(countname)) {File file=new File(countname+".txt");FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加 StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(jta1.getText()+"\r\n");out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();          //关闭}}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;/*** 本类实现对转账的操作, 注意金额的处理* * **/
public class Transfer extends JFrame implements ActionListener{String countname;JButton jb1, jb2, jb3;  //按钮JLabel jlb1, jlb2, jlb3; //标签JTextArea jta1,jta2;    //文本框JTextField jtf1;     //单行文本JPanel jp1;JButton jb100,jb200,jb500,jb1000;private NewButton button;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);       //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public Transfer(String countname) {this.countname = countname;Background();jb1 = new NewButton("确定");jb2 = new NewButton("重置");jb100 = new NewButton("100");jb200 = new NewButton("200");jb500 = new NewButton("500");jb1000 = new NewButton("1000");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jb100.addActionListener(this);jb200.addActionListener(this);jb500.addActionListener(this);jb1000.addActionListener(this);jlb1 = new JLabel("请输入存入金额:");  //添加标签jlb2 = new JLabel("对方账号");//创建文本框jta1 = new JTextArea();   //转出金额jtf1 = new JTextField(13);//对方账户加入面板jp1 = new JPanel();jp1.add(jlb2);jp1.add(jtf1);//设置布局this.setTitle("转账");this.setLayout(null);this.setSize(310, 310); //创建对方账户的标签jp1.setBounds(100, 20, 150, 60);//存入标签和文本框jlb1.setBounds(100, 100, 110, 25);jta1.setBounds(100, 120, 150, 50);jta1.setFont(new   java.awt.Font("Dialog",   0,   15));//确定和重置按钮jb1.setBounds(100, 190, 62, 28);jb2.setBounds(170, 190, 62, 28);jb100.setBounds(7, 40, 70, 30);jb200.setBounds(7, 90, 70, 30);jb500.setBounds(7, 140, 70, 30);jb1000.setBounds(7, 190, 70, 30);this.add(jp1);this.add(jlb1);this.add(jta1);this.add(jb1);this.add(jb2);this.add(jb100);this.add(jb200);this.add(jb500);this.add(jb1000);this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);  //设置不可拉伸大小}//清空账号和密码框private void clear() {// TODO Auto-generated method stubjtf1.setText("");jta1.setText("");    //设置为空}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand()=="100"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="200"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="500"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="1000"){jta1.setText(e.getActionCommand());}if (e.getActionCommand()=="确定"){try {transfer();} catch (IOException e1) {e1.printStackTrace();}}else if (e.getActionCommand()=="重置"){clear();}}private void transfer() throws IOException {if (jta1.getText().isEmpty()){JOptionPane.showMessageDialog(null, "金额为空,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if (jtf1.getText().isEmpty()){JOptionPane.showMessageDialog(null, "转入账号,请重新输入!","消息提示",JOptionPane.WARNING_MESSAGE);}else if(new Check().checkmoney(jta1.getText()))  //验证金额是否合法{if(new Check().check2(jtf1.getText()))   //验证账户是否存在{//将本人账户名 对方账户名和金额传递过去new TransferToOthers(countname,jtf1.getText(),jta1.getText());  clear();}else {JOptionPane.showMessageDialog(null, "账户不存在","消息提示",JOptionPane.WARNING_MESSAGE);clear();}}else {JOptionPane.showMessageDialog(null, "金额不合法","消息提示",JOptionPane.WARNING_MESSAGE);clear();}}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;import javax.swing.ImageIcon;
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;public class TransferToOthers extends JFrame implements ActionListener{JButton jb1, jb2, jb3;  //按钮JLabel jlb1, jlb2, jlb3,jlb4;  //标签JTextField jtf1,jtf2,jtf3;   //文本框JPasswordField jpf; //密码框JPanel jp1,jp2,jp3,jp4;      //面板String wantsave,countname,mycountname;//private boolean flag;JLabel label;//背景标签ImageIcon background;//背景JPanel myPanel;//面板public void Background() {background = new ImageIcon("背景01.jpg");label = new JLabel(background);        //把背景图片添加到标签里label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());  //把标签设置为和图片等高等宽myPanel = (JPanel)this.getContentPane();        //把我的面板设置为内容面板myPanel.setOpaque(false);                 //把我的面板设置为不可视   this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));       //把标签添加到分层面板的最底层}public TransferToOthers(String mycountname, String countname, String wantsave) throws IOException {Background();this.wantsave = wantsave;this.countname = countname;this.mycountname = mycountname;jb1 = new JButton("确定");jb2 = new JButton("取消");//设置按钮监听jb1.addActionListener(this);jb2.addActionListener(this);//标签信息jlb1 = new JLabel("对方姓名");jlb2 = new JLabel("身份证号");jlb3 = new JLabel("        账号");jlb4 = new JLabel("请确认对方账户信息");jlb4.setFont(new   java.awt.Font("Dialog",   1,   15));jtf1 = new JTextField(13);jtf2 = new JTextField(13);jtf3 = new JTextField(13);jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jp4 = new JPanel();jp1.add(jlb1);jp1.add(jtf1);jp2.add(jlb2);jp2.add(jtf2);jp3.add(jlb3);jp3.add(jtf3);jp4.add(jb1);jp4.add(jb2);//设置布局this.setTitle("确认信息");this.setLayout(null);jlb4.setBounds(65, 20, 300 ,50);jp1.setBounds(-10, 80, 300 ,50);jp2.setBounds(-10, 150, 300 ,50);jp3.setBounds(-10, 220, 300 ,50);jp4.setBounds(-10, 290, 300 ,50);//将JPane加入JFrame中  this.add(jp1);  this.add(jp2);  this.add(jp3);this.add(jp4);this.add(jlb4);this.setSize(300, 400);   //设置窗体大小this.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);  //设置仅关闭当前窗口this.setVisible(true);  //设置可见this.setResizable(false);  //设置不可拉伸大小String []message = new UserMessage().read(countname);//将姓名的第一个字变为*message[0] ="*"+message[0].substring(1,message[0].length());//将身份证号第6到12位变成*message[1] =message[1].substring(0,6)+"*******"+message[1].substring(13,message[1].length());jtf1.setText(message[0]);jtf2.setText(message[1]);jtf3.setText(countname);}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getActionCommand()=="确定"){String nowmoney="";try {//记录明细File file=new File(mycountname+".txt");FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加 StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(new java.util.Date()+"    "+"-"+wantsave+" 转账支出   "+"\r\n");out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();           //关闭nowmoney = new UserMessage().updatemoney(mycountname,-Integer.parseInt(wantsave));} catch (NumberFormatException e2) {e2.printStackTrace();} catch (IOException e2) {e2.printStackTrace();}if (!nowmoney.equals("负数")){//jta2.setText("您的余额为:\n "+nowmoney);//jta1.setText("");//对方账户存钱try {//记录明细File file=new File(countname+".txt");FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加 StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(new java.util.Date()+"    "+"+"+wantsave+" 转账收入   "+"\r\n");out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();         //关闭nowmoney = new UserMessage().updatemoney(mycountname,Integer.parseInt(wantsave));  //源代码写错了 已更正} catch (NumberFormatException e1) {e1.printStackTrace();} catch (IOException e1) {e1.printStackTrace();}if (!nowmoney.equals("负数")){JOptionPane.showMessageDialog(null, "存入成功,您的余额为:"+nowmoney+" 数科币","消息提示",JOptionPane.PLAIN_MESSAGE);dispose();}}else {JOptionPane.showMessageDialog(null, "余额不足请重新输入:","消息提示",JOptionPane.WARNING_MESSAGE);dispose();}}else if (e.getActionCommand()=="取消"){dispose();}}}

import java.io.*;
/*** 此类事对用户信息的 写入和读取操作* * **/
public class UserMessage
{/** 将注册的信息写入文本*/public void write(String[] message)throws IOException{File file=new File("Message.txt");String messagesum="";for (int i=0; i<5; i++)  //将信息格式化存储messagesum+=message[i]+"~";if(!file.exists())file.createNewFile();FileOutputStream out=new FileOutputStream(file,true); //建立输出对象,true表示追加       StringBuffer sb=new StringBuffer();      //创建字符串流sb.append(messagesum+"\n");              //向字符串流中添加信息out.write(sb.toString().getBytes("gb2312"));         //将字符串流中的信息写入文本out.close();          //关闭}/**   读取信息,将用户名信息返回(如果不存在返回null),和Check类配合使用  */public String[] read(String countname) throws IOException{File file=new File("Message.txt");if(!file.exists()||file.isDirectory())throw new FileNotFoundException();BufferedReader br=new BufferedReader(new FileReader(file));String temp=null;StringBuffer sb=new StringBuffer();temp=br.readLine();String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证while(temp!=null){String sbstring = temp.toString();int n = sbstring.length();            //测字符串长度for (int i=0; i<5; i++)message[i] = "";int k=0;for (int i=0; i<n; i++){if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (message[2].equals(countname))  //返回找到用户的信息{return message;}temp=br.readLine();}return null;}/*在存款取款操作 时 更新金额* */public String updatemoney(String countname,int wangsave) throws IOException{File file=new File("Message.txt");if(!file.exists()||file.isDirectory())throw new FileNotFoundException(); //读文件  BufferedReader br=new BufferedReader(new FileReader(file));String temp=null;StringBuffer sb=new StringBuffer();  //建立字符串流StringBuffer sb1=new StringBuffer();String moneystring="";temp=br.readLine();String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证while(temp!=null){String sbstring = temp.toString();int n = sbstring.length();            //测字符串长度for (int i=0; i<5; i++)message[i] = "";int k=0;for (int i=0; i<n; i++)      //拆乘5个String{if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (message[2].equals(countname))   //找到该账户名{String newmessage="";int moneyint;moneyint=Integer.parseInt(message[4])+wangsave;  //金额转为int操作//原金额                                   //存入金额if (moneyint<0){return "负数";}moneystring  = String.valueOf(moneyint); //将String转intfor (int i=0; i<4; i++)              //转化为规定格式文件 newmessage += message[i]+"~";newmessage += moneystring+"~";sb1.append(newmessage+"\n");}else{sb1.append(temp+"\n");}temp=br.readLine();}/** 说明:* 本来的想法是在原文件对象中覆盖内容,但是发现覆盖后文本为空, 无法解决* 但重新创建文件对象,则可以完成操作*/File file1=new File("Message.txt");   //重新建立文件对象, 覆盖写入文本if(!file1.exists())file1.createNewFile();FileOutputStream out=new FileOutputStream(file1,false);  //false为重写操作out.write(sb1.toString().getBytes("gb2312"));out.close();return moneystring;}////更新密码public String updatepwd(String countname,String pwd) throws IOException{File file=new File("Message.txt");if(!file.exists()||file.isDirectory())throw new FileNotFoundException(); //读文件  BufferedReader br=new BufferedReader(new FileReader(file));String temp=null;StringBuffer sb=new StringBuffer();//写文件//FileOutputStream out=new FileOutputStream(file,false);        StringBuffer sb1=new StringBuffer();String moneystring="";temp=br.readLine();String []message = new String[5];     //按~拆分 成5个字符串数组,按账号和密码进行信息验证while(temp!=null){String sbstring = temp.toString();int n = sbstring.length();            //测字符串长度for (int i=0; i<5; i++)message[i] = "";int k=0;for (int i=0; i<n; i++)      //拆乘5个String{if(sbstring.charAt(i)=='~'){//System.out.println("@"+message[k]);k++;}else {message[k] += sbstring.charAt(i);}}if (message[2].equals(countname))   //找到该账户名{//修改密码for (int i=0; i<3; i++)sb1.append(message[i]+"~");sb1.append(pwd+"~");sb1.append(message[4]+"~\n");}else{sb1.append(temp+"\n");}temp=br.readLine();}/** 说明:* 本来的想法是在原文件对象中覆盖内容,但是发现覆盖后文本为空, 无法解决* 但重新创建文件对象,则可以完成操作*/File file1=new File("Message.txt");if(!file1.exists())file1.createNewFile();FileOutputStream out=new FileOutputStream(file1,false);out.write(sb1.toString().getBytes("gb2312"));out.close();return moneystring;}}

第一次写博客,还不太会运用工具,是个笨比。

如果这篇文章对你有帮助,还请一键三连【开心】【开心】

银行账户管理系统GUI相关推荐

  1. 【MyBatis】第五课 银行账户管理系统网站开发

    概念 本文是根据Jsp以及Servlet课程,结合MyBatis框架的综合运用,开发一个小项目网站,使用MVC+三层架构的项目搭建方式来编写本文文章. 1.数据库的创建 本文使用MySQL数据搭建数据 ...

  2. 项目名称:Bank Account Management System 银行账户管理系统 简称BAM

    有兴趣的高手可以发表一下代码   供我们初级者借鉴借鉴 项目名称:Bank Account Management System 银行账户管理系统 简称BAM 项目描述:这是一个银行账户管理系统,用户可 ...

  3. 设计一个银行账户管理系统

    **欢迎使用小辉辉建设银行** 银行账户 注册账号 登录 请选择你要执行的银行业务 银行账户管理系统,使用HashMap函数做出来要比较容易一些,而我没有用到哈哈,这个系统开始搞的时候,还没有学到ha ...

  4. 基于Java的银行账户管理系统

    一.项目介绍 基于Java GUI的银行账户信息管理系统,可直接启动演示.包含账户查询.开户.销户.存款.取款.账户统计等功能.适合作为课程设计.大作业.毕业设计项目. 二.技术介绍: Java;Sp ...

  5. 银行账户管理系统c语言链表,课程设计银行储蓄管理系统Word版

    <课程设计银行储蓄管理系统Word版>由会员分享,可在线阅读,更多相关<课程设计银行储蓄管理系统Word版(22页珍藏版)>请在人人文库网上搜索. 1.传播优秀Word版文档 ...

  6. 课程设计-银行账户管理系统

    编程实现:(仔细业务之间的包含关系,并完成以下编程需求,要适当提高代码的可复用性.) 用户:账号(int:系统随机产生8位数字).姓名(str).密码(int:6位数字).地址.存款余额(int).开 ...

  7. 【Java】银行账户管理系统

    系统实现: 开发语言是Java,开发平台是eclipse,通过文件储存数据,借助Java的GUI来实现交互.自己来写界面的话当然比较烦,于是我用的eclipse的插件WindowBuilder,通过可 ...

  8. 个人银行账户管理系统

    #include <bits/stdc++.h> #include <iostream> #include <cstring> #include <cstdl ...

  9. 银行账户管理系统(一)

    一个活期储蓄帐户包括账号(id),余额(balance),年利率(rate)等信息,还包括显示账户信息(show),存款(desposit),取款(withdraw),结算利息(settle)等操作. ...

  10. c#设计一个Windows应用程序,模拟一个简单的银行账户管理系统。完成“创建账A款”“存款”和“查询余额”的模拟操作。程序功能如下:

    (1)当单击"创建账户"按钮时,显示如图4-24所示信息,其中,卡号为随机生成的一100000-499 999的一个值,余额初始化为100元. (2)在"取款" ...

最新文章

  1. 练习2:课工场响应式导航条_作业帮直播课APP下载最新版入口
  2. C语言基础知识【数据类型】
  3. 【Java文件操作(一)】递归打印文件目录
  4. Java命令行界面(第23部分):Rop
  5. TCP中recv解阻塞的两种方式
  6. Oracle归档日志(翻译)
  7. NumPy、TensorFlow和scikit-learn简介
  8. wordpress python 采集_Python3利用Selenium3模拟wordpress博客登陆
  9. code block下使用openMP
  10. 小蚂蚁学习C语言(2)——C语言编程预备知识(上)
  11. java编码规范试题_java编码规范考试题答案完整版.doc
  12. 基于LED的室内可见光通信系统
  13. 电压、电流检测方法介绍
  14. TJA1403状态模式
  15. c++ 聚合/POD/平凡/标准布局 介绍
  16. 如何以活动价在官网购买百度网盘会员
  17. 如何实现开票申请及其审核功能
  18. (五)2.自动控制原理 Frequency Responce Methods 之 Nyquist曲线
  19. android 微信摇一摇功能实现,android 类似微信的摇一摇功能实现思路及代码
  20. 如何更改计算机任务栏图标,win7修改任务栏图标|win7系统如何将任务栏图标变大...

热门文章

  1. DeepFace介绍
  2. 2021 大学生电子设计竞赛 G题 无人机 识别部分
  3. 数学建模之方差分析基础--单因素,双因素方差分析与matlab实现
  4. Latex中使用BibTex插入参考文献
  5. SpringCloud项目启动
  6. excel文件保护忘记密码解除
  7. win10系统 笔记本 插入耳机有声音,外放无声音
  8. SAR图像:拟合杂波时常用的分布
  9. 基于FusionInsight Manager的大数据架构图
  10. 如何导出html中的图片,一键保存网页中的全部图片