银行账户管理系统GUI

一个简单的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();   //转化为string
        	int 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();   //转化为string
        	int 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();   //转化为string
        	int 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();
		}
	}
	
	
	
	
	
	
	
	
	
	@Override
	public 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("");  
			
		}

	@Override
	public 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]+" 数科币");
	    
	    
	    
	    
	}
	
	@Override
	public 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);	//设置不可拉伸大小
	}
	
	@Override
	public 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);	//设置不可拉伸大小
		
	}

	@Override
	public 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);	//设置不可拉伸大小
	   
	    
	}
	
	
	


	@Override
	public 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 block
				e1.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);	//设置不可拉伸大小
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getActionCommand()=="确定")
		{
			
			try {
				modify();  //进行信息核对
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}  
		}
		else if (e.getActionCommand()=="重置")
		{
			clear();   //清楚信息
		}
		
	}

	private void modify() throws IOException {
		// TODO Auto-generated method stub
		if (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 stub
		jtf1.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();
		}
	}

	@Override
	public 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);	//设置不可拉伸大小
		
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getActionCommand()=="确定")
		{
			try {
				register();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.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 stub
		jtf1.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,1
        this.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);	//设置不可拉伸大小
		
	}

	@Override
	public 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("");  
			
		}

	@Override
	public 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 stub
		jtf1.setText("");
		jta1.setText("");    //设置为空
			
	}

	@Override
	public 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);
	    
	    
	    
	    
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (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转int
        		for (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;
	}
	
	
	
	
	

}

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

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YOUNG.K

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值