Java编写的记账本

标签: java 记账本 界面 GUI
1877人阅读 评论(0) 收藏 举报
分类:
*/
 * Copyright (c) 2016,烟台大学计算机与控制工程学院
 * All rights reserved.
 * 文件名:text.java
 * 作者:常轩
 * 微信公众号:Worldhello
 * 完成日期:2016年12月27日
 * 版本号:V1.0
 * 程序输入:无
 * 程序输出:见运行结果
 */

/*
功能概述:
记录个人的收入和支出,自动记录时间。图形界面,需要先进行注册再登陆,登陆不同的账号记录不同的收支情况,极大的保护了个人的隐私,等。
因为本程序中需要用到一些图片资源,只是上传部分代码(代码也不太全,仅供参考),如需获取整个项目的代码和资源,请关注微信众号:Worldhello   后台回复:记账本   即可获得完整项目的压缩包
*/






package com.ytcx.ui;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JFrame.*;
import javax.swing.table.DefaultTableModel;

import com.ytcx.server.Operation;
import com.ytcx.util.Tool;
public class UserWindow extends JFrame{
	private final String str=null;
	private  String fileStr=null;
	Operation oper=null;
	

	private JTable table=new JTable();
	private DefaultTableModel dtm=new DefaultTableModel();
	Vector colName=new Vector();
	private JComboBox typeCom=new JComboBox();
	private JTextField moneyTxt=new JTextField();
	private JTextField remarkTxt=new JTextField();
	private String id;
	private String time;
	public UserWindow(String str,String fileStr){
		
		this.fileStr=fileStr;
		oper=new Operation(fileStr);
		setTitle("欢迎用户"+str+"使用记账本");
		this.setIconImage(new ImageIcon("note.png").getImage());
		setBounds(50,50,900,600);
		init();
		setVisible(true);
	}
	void init(){
		JScrollPane sp=new JScrollPane(setTable());
		final JSplitPane jsp=new JSplitPane(JSplitPane.VERTICAL_SPLIT,sp,setInfo());
		jsp.addComponentListener(new ComponentAdapter(){
			public void componentResized(ComponentEvent e){
				jsp.setDividerLocation(0.5);
			}
		});
		this.add(jsp);
		//showUserImage=new ImageIcon(this.getClass().getResource("notes.png"));
		
		
	}

	public JTable setTable(){
		
		colName.add("流水号");
		colName.add("类型");
		colName.add("金额");
		colName.add("日期");
		colName.add("备注");
		Vector data=oper.select();
		dtm.setDataVector(data, colName);
		table.setModel(dtm);
		
		table.addMouseListener(new MouseListener(){
			public void mouseClicked(MouseEvent arg0) {
				int row=table.getSelectedRow();
				id=dtm.getValueAt(row, 0).toString();
				//测试语句System.out.println(id);
				String type=dtm.getValueAt(row, 1).toString();
				String money=dtm.getValueAt(row, 2).toString();
				String remark=dtm.getValueAt(row, 4).toString();
				typeCom.setSelectedItem(type);
				moneyTxt.setText(money);
				remarkTxt.setText(remark);
				time=dtm.getValueAt(row, 3).toString();
			}
			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}});
		return table;
	}
	/*public static void main(String[] args) {
		new UserWindow();
	}*/
	public JPanel setInfo(){
		JPanel jp=new JPanel();
		jp.setLayout(null);
		
		JLabel label1=new JLabel("类型");
		label1.setBounds(20, 50, 50, 30);
		jp.add(label1);
		typeCom.addItem("收入");
		typeCom.addItem("支出");
		typeCom.setBounds(80,50,60,30);
		
		JLabel label2=new JLabel("金额");
		label2.setBounds(200,50,50,30);
		jp.add(label2);
		moneyTxt.setBounds(250,50,100,30);
		
		JLabel label3=new JLabel("备注");
		label3.setBounds(380,50,50,30);
		jp.add(label3);
		remarkTxt.setBounds(420,50,100,30);
		
		JButton button1=new JButton("修改");
		button1.setBounds(50, 100, 100, 50);
		button1.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				String type=typeCom.getSelectedItem().toString();
				String money=moneyTxt.getText();
				String remark=remarkTxt.getText();
				Tool tool=new Tool();
				String time=tool.getTime();
				oper.update(id, type, money, time, remark);
				/*
				 * 表格刷新
				 */
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}});
		
		JButton button2=new JButton("增加");
		button2.setBounds(150, 100, 100, 50);
		button2.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				String type=typeCom.getSelectedItem().toString();
				String money=moneyTxt.getText();
				String remark=remarkTxt.getText();
				Tool tool=new Tool();
				int id=tool.getNewId();
				String time=tool.getTime();
				String data=id+" "+type+" "+money+" "+time+" "+remark+"\n";
				oper.add(data);
				/*
				 * 表格刷新
				 */
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		JButton button3=new JButton("删除");
		button3.setBounds(250, 100, 100, 50);
		button3.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				oper.delete(id);
				/*
				 * 表格刷新
				 */
				
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		jp.add(remarkTxt);
		jp.add(moneyTxt);
		jp.add(typeCom);
		jp.add(button1);
		jp.add(button2);
		jp.add(button3);
		return jp;
	}
}


package com.ytcx.ui;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JFrame.*;
import javax.swing.table.DefaultTableModel;

import com.ytcx.server.Operation;
import com.ytcx.util.Tool;
public class UserWindow extends JFrame{
	private final String str=null;
	private  String fileStr=null;
	Operation oper=null;
	

	private JTable table=new JTable();
	private DefaultTableModel dtm=new DefaultTableModel();
	Vector colName=new Vector();
	private JComboBox typeCom=new JComboBox();
	private JTextField moneyTxt=new JTextField();
	private JTextField remarkTxt=new JTextField();
	private String id;
	private String time;
	public UserWindow(String str,String fileStr){
		
		this.fileStr=fileStr;
		oper=new Operation(fileStr);
		setTitle("欢迎用户"+str+"使用记账本");
		this.setIconImage(new ImageIcon("note.png").getImage());
		setBounds(50,50,900,600);
		init();
		setVisible(true);
	}
	void init(){
		JScrollPane sp=new JScrollPane(setTable());
		final JSplitPane jsp=new JSplitPane(JSplitPane.VERTICAL_SPLIT,sp,setInfo());
		jsp.addComponentListener(new ComponentAdapter(){
			public void componentResized(ComponentEvent e){
				jsp.setDividerLocation(0.5);
			}
		});
		this.add(jsp);
		//showUserImage=new ImageIcon(this.getClass().getResource("notes.png"));
		
		
	}

	public JTable setTable(){
		
		colName.add("流水号");
		colName.add("类型");
		colName.add("金额");
		colName.add("日期");
		colName.add("备注");
		Vector data=oper.select();
		dtm.setDataVector(data, colName);
		table.setModel(dtm);
		
		table.addMouseListener(new MouseListener(){
			public void mouseClicked(MouseEvent arg0) {
				int row=table.getSelectedRow();
				id=dtm.getValueAt(row, 0).toString();
				//测试语句System.out.println(id);
				String type=dtm.getValueAt(row, 1).toString();
				String money=dtm.getValueAt(row, 2).toString();
				String remark=dtm.getValueAt(row, 4).toString();
				typeCom.setSelectedItem(type);
				moneyTxt.setText(money);
				remarkTxt.setText(remark);
				time=dtm.getValueAt(row, 3).toString();
			}
			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}});
		return table;
	}
	/*public static void main(String[] args) {
		new UserWindow();
	}*/
	public JPanel setInfo(){
		JPanel jp=new JPanel();
		jp.setLayout(null);
		
		JLabel label1=new JLabel("类型");
		label1.setBounds(20, 50, 50, 30);
		jp.add(label1);
		typeCom.addItem("收入");
		typeCom.addItem("支出");
		typeCom.setBounds(80,50,60,30);
		
		JLabel label2=new JLabel("金额");
		label2.setBounds(200,50,50,30);
		jp.add(label2);
		moneyTxt.setBounds(250,50,100,30);
		
		JLabel label3=new JLabel("备注");
		label3.setBounds(380,50,50,30);
		jp.add(label3);
		remarkTxt.setBounds(420,50,100,30);
		
		JButton button1=new JButton("修改");
		button1.setBounds(50, 100, 100, 50);
		button1.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				String type=typeCom.getSelectedItem().toString();
				String money=moneyTxt.getText();
				String remark=remarkTxt.getText();
				Tool tool=new Tool();
				String time=tool.getTime();
				oper.update(id, type, money, time, remark);
				/*
				 * 表格刷新
				 */
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}});
		
		JButton button2=new JButton("增加");
		button2.setBounds(150, 100, 100, 50);
		button2.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				String type=typeCom.getSelectedItem().toString();
				String money=moneyTxt.getText();
				String remark=remarkTxt.getText();
				Tool tool=new Tool();
				int id=tool.getNewId();
				String time=tool.getTime();
				String data=id+" "+type+" "+money+" "+time+" "+remark+"\n";
				oper.add(data);
				/*
				 * 表格刷新
				 */
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		JButton button3=new JButton("删除");
		button3.setBounds(250, 100, 100, 50);
		button3.addMouseListener(new MouseListener(){

			@Override
			public void mouseClicked(MouseEvent arg0) {
				oper.delete(id);
				/*
				 * 表格刷新
				 */
				
				Vector dataSel=oper.select();
				dtm.setDataVector(dataSel, colName);
				table.setModel(dtm);
			}

			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		jp.add(remarkTxt);
		jp.add(moneyTxt);
		jp.add(typeCom);
		jp.add(button1);
		jp.add(button2);
		jp.add(button3);
		return jp;
	}
}



package com.ytcx.server;

import java.util.Vector;

import com.ytcx.io.FileIO;
import com.ytcx.io.FileIOImp;
import com.ytcx.util.Tool;

public class Operation {
	FileIO io=new FileIOImp();
	Tool tool=new Tool();
	public Operation(String filename){
		io.checkFile(filename);
	}
	public Vector select() {
		String data=io.read();
		//System.out.println("lala,看看进来执行没有?");  测试语句
		return tool.StringToVec(data);
		// TODO Auto-generated method stub
	
	}

	public void add(String data){
		io.write(data, true);
	}
	
	public void delete(String id){
		Vector vecBig=select();
		//System.out.println("删除了没有?");  //测试
		for(int i=0;i<vecBig.size();i++){
			Vector vecSmall=(Vector)vecBig.get(i);
			//测试语句System.out.println("+1");
			if(vecSmall.get(0).toString().equals(id)){
				vecBig.remove(i);
			//	System.out.println("理论上已经删除");  //测试
				break;
			}
				
		}
		String data=tool.VecToString(vecBig);
		io.write(data, false);
	}
	public void update(String id,String type,String money,String time,String remark){
		Vector vecBig =select();
		for(int i=0;i<vecBig.size();i++){
			Vector vecSmall=(Vector)vecBig.get(i);
			if(vecSmall.get(0).toString().equals(id)){
				vecSmall.removeAllElements();
				vecSmall.add(id);
				vecSmall.add(type);
				vecSmall.add(money);
				vecSmall.add(time);
				vecSmall.add(remark);
				break;
			}
		}
		String data=tool.VecToString(vecBig);
		io.write(data, false);
	}

}

运行图片:



查看评论

JAVA基础项目-家庭记账软件

  • 2015年09月24日 21:09
  • 35KB
  • 下载

java 开发的记账本(包含代码与运行程序)

  • 2010年10月08日 20:26
  • 966KB
  • 下载

Java编写的记账本

*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.java * 作者:常轩 * 微信公众号:W...
  • vcx08
  • vcx08
  • 2016-12-30 14:56:44
  • 1877

[Java + Oracle + Tomcat] 个人记账[网页版]

实现的功能点: 1.登录用户名、密码和验证码验证; 2.第二次登录自动记住用户名; 3.欢迎页面提示上次登录时间; 4.消费信息查询页面分页; 5.新增、删除、修改消费记录; 6.防止盗连...
  • sparrow00004
  • sparrow00004
  • 2014-12-11 10:05:23
  • 984

个人记账本(Java)

  • 2017年02月13日 12:33
  • 4.66MB
  • 下载

【转】JAVA记账本程序源码

刚开始学java的时候,做了个swing小程序,一晚上做出来后感觉挺不错的,对swing了解深了些,也可以自己用这个小程序来记账省钱。手敲的界面代码;个人感觉JAVA swing的界面代码挺容易理解的...
  • yatyou
  • yatyou
  • 2013-12-11 10:58:00
  • 3908

JAVA 家庭收支管理程序

简单的家庭收支管理程序  主要练习按钮响应  文件输出 读取 import java.io.*; import java.awt.*; import java.awt.event.Actio...
  • u011699990
  • u011699990
  • 2016-12-23 09:49:28
  • 1006

JAVA基础开发案例--管家记账

从今天起,我们来运用JAVA基础加数据库mysql开发一个管家记账功能。它具有查看所有记录,多条件查询,编辑,添加,删除等功能。前期准备:开发工具:eclipsejar包:第一个数据库池连接组件第二个...
  • qq_37561761
  • qq_37561761
  • 2018-03-03 17:19:06
  • 56

java记账本

  • 2014年05月09日 21:14
  • 966KB
  • 下载

网页版记账本[java+oracle]

  • 2015年01月11日 21:27
  • 1.47MB
  • 下载
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 13万+
    积分: 3328
    排名: 1万+
    微信公众号
    课程设计、视频资源、有料趣文
    Worldhello


    微信公众号:Worldhello
    期待您的关注!
    博客专栏
    最新评论