特简单的财务管理小程序

个人财务管理小软件

这是个十分简单的个人财务管理小软件,基本只有将花费相加现实总和的功能。
这是自己之前做的一个作业,做的时候在博客上搜了一下。发现博客上的程序功能都太高大上全了。不像是自己能写出来的,因此自己写了一个。

```java`import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.*;
import javax.swing.JTextArea;

public class Window3 extends JFrame {

private JPanel contentPane;
private final JComboBox comboBox = new JComboBox();
private final JComboBox comboBox_1 = new JComboBox();
private JTextField textField;
private JTextField textField_2;
ReaderListen listener;
MonthMoneyListen listener_1;
private JButton button;

/**
 * Launch the application.
 * @param args  这是调用参数
 * @author
 * @since 1.0
 * 
 */
public static void main(String[] args) {
	/**
	 * 
	 */
	EventQueue.invokeLater(new Runnable() {
		public void run() {
			try {
				Window3 frame = new Window3();
				frame.setTitle("个人财务管理小软件");
				frame.setVisible(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
}

/**
 * Create the frame.
 */
public Window3() {
	listener=new ReaderListen();
	listener_1=new MonthMoneyListen();
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(100, 100, 692, 501);
	contentPane = new JPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	setContentPane(contentPane);
	contentPane.setLayout(null);
	comboBox.setBounds(14, 84, 154, 36);
	contentPane.add(comboBox);
	init();			//对日期标记
	JLabel lblNewLabel = new JLabel("\u65E5\u671F");
	lblNewLabel.setBounds(14, 38, 103, 33);
	contentPane.add(lblNewLabel);
	
	JLabel lblNewLabel_1 = new JLabel("\u6D88\u8D39\u9879\u76EE");
	lblNewLabel_1.setBounds(14, 179, 103, 36);
	contentPane.add(lblNewLabel_1);
	
	comboBox_1.setBounds(14, 228, 154, 36);
	contentPane.add(comboBox_1);
	init1();		//对消费类型标记
	getContentPane().add(comboBox_1);
	
	JLabel lblNewLabel_2 = new JLabel("\u6D88\u8D39\u91D1\u989D");
	lblNewLabel_2.setBounds(241, 179, 133, 33);
	contentPane.add(lblNewLabel_2);
	
	JTextField textField;
	textField = new JTextField();  //消费金额那个框
	textField.setBounds(241, 229, 156, 34);
	contentPane.add(textField);
	textField.setColumns(10);
	listener.setJTextFieldMoney(textField);
	textField.addActionListener(listener);
	
	JLabel lblNewLabel_3 = new JLabel("\u6D88\u8D39\u603B\u91D1\u989D");
	lblNewLabel_3.setBounds(14, 304, 96, 36);
	contentPane.add(lblNewLabel_3);
	
	JLabel lblNewLabel_4 = new JLabel("\u6708\u751F\u6D3B\u8D39");
	lblNewLabel_4.setBounds(241, 41, 103, 26);
	contentPane.add(lblNewLabel_4);
	
	textField_2 = new JTextField();		//月生活费那个框
	textField_2.setBounds(241, 84, 154, 36);
	contentPane.add(textField_2);
	textField_2.setColumns(10);
	listener_1.setListen(listener);
	listener_1.setJTextFieldMonthMoney(textField_2);
	textField_2.addActionListener(listener_1);
	listener.setJTextFieldMonthMoney(textField_2);
	
	JLabel lblNewLabel_5 = new JLabel("\u5269\u4F59\u91D1\u989D");
	lblNewLabel_5.setBounds(241, 304, 96, 36);
	contentPane.add(lblNewLabel_5);
	
	button = new JButton("\u786E\u8BA4");  	//确认按钮
	button.addActionListener(listener);
	button.setBounds(475, 353, 154, 45);
	contentPane.add(button);
	
	JTextArea textArea = new JTextArea();		//消费总金额那个框
	textArea.setBounds(14, 353, 154, 55);
	listener.setJTextArea(textArea);
	contentPane.add(textArea);
	
	JTextArea textArea_1 = new JTextArea();		//剩余金额那个框
	textArea_1.setBounds(241, 353, 154, 55);
	listener.setJTextArea_1(textArea_1);
	contentPane.add(textArea_1);
	
	
	JTextArea textArea_2 = new JTextArea();		//警告那个框
	textArea_2.setBounds(492, 84, 114, 207);
	listener.setJTextArea_2(textArea_2);
	contentPane.add(textArea_2);
}
/**
 * 对日期的操作
 */
void init() {
	for(int i=1;i<=30;i++)
		comboBox.addItem(i);
	getContentPane().add(comboBox);
}
/**
 * 对消费项目的操作
 */
void init1() {
	comboBox_1.addItem("吃饭");
	comboBox_1.addItem("交通");
	comboBox_1.addItem("娱乐");
	comboBox_1.addItem("其他");
	getContentPane().add(comboBox_1);
}

}
/**

  • 监视月生活费的监视器
  • @author

*/

class MonthMoneyListen implements ActionListener{
JTextField MonthMoney;
ReaderListen listener;
public void setListen(ReaderListen listener) {
this.listener=listener;
}
public void setJTextFieldMonthMoney(JTextField textField) {
MonthMoney=textField;
}
public void actionPerformed(ActionEvent e) {
listener.setJTextFieldMonthMoney(MonthMoney);
}

}
/**

  • 监视确认按钮的监视器以及监视消费金额框的监视器

*/
class ReaderListen implements ActionListener{
public static double sum;
public static double rest;
JTextArea textShow;
JTextArea textShow_1;
JTextArea textShow_2;
JTextField Money;
JTextField MonthMoney;
public void setJTextFieldMoney(JTextField textField) {
Money=textField;
}
public void setJTextFieldMonthMoney(JTextField textField) {
MonthMoney=textField;
}
public void setJTextArea(JTextArea area) {
textShow=area;
}
public void setJTextArea_1(JTextArea area) {
textShow_1=area;
}
public void setJTextArea_2(JTextArea area) {
textShow_2=area;
}
public void actionPerformed(ActionEvent e) {
double i=Double.parseDouble(Money.getText());
double j=Double.parseDouble(MonthMoney.getText());
sum+=i;
rest=j-sum;
Money.setText(""); //自动清空消费金额输入框
textShow.setText("");
textShow.append(sum+"\t");
textShow_1.setText("");
textShow_1.append(rest+"\t");
if((sum/j)>=1) {
textShow_2.setText("");
textShow_2.append(“警告!超过预算!”);
}
else if((sum/j)>=0.8) {
textShow_2.setText("");
textShow_2.append(“警告!花钱超过八成!”);
}
else if((sum/j)>=0.5) {
textShow_2.setText("");
textShow_2.append(“注意!花钱超过半数!”);
}
else {
textShow_2.setText("");
textShow_2.append(“暂无危机,放心花!”);
}

}

}
`


  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值