package yonghu;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.Box;
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.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import Index.Login;
import yonghu.Xiangxi;
import yonghu.Luru;
import Util.DbUtil;
public class zhumain extends JFrame implements ActionListener {
JTable table;
JLabel label1,label2,label3,label4;
Object a[][];
Object name[] = {"序号","方式","类型","金额","收入或支出","用户"};
JButton buttonOfzhichu,buttonOfshouru,buttonOfchaxun,buttonOfLogout,buttonOfXiangXi,buttonOfheji;
Box box1,box2;
JComboBox Clabel;
TableModel tabledata;
JTextField field;
JPanel jPanel4,jPanel5;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String username =null;
public zhumain(String username) {
init();
setVisible(true);
setBounds(500, 200, 700, 400);
setTitle("用户界面");
this.username=username;
}
public zhumain(boolean success) {
init();
setVisible(true);
setBounds(500, 200, 700, 400);
setTitle("用户界面");
if(success)
{
xinXiLiuLan();
}
}
void init() {
label1=new JLabel("家庭理财系统");
buttonOfheji =new JButton("合计");
buttonOfheji .addActionListener(this);
buttonOfzhichu = new JButton(" 支出 ");
buttonOfzhichu .addActionListener(this);
buttonOfshouru = new JButton(" 收入 ");
buttonOfshouru .addActionListener(this);
buttonOfLogout = new JButton(" 退 出 登 录 ");
buttonOfLogout.addActionListener(this);
buttonOfXiangXi = new JButton(" 详 细 信 息 ");
buttonOfXiangXi.addActionListener(this);
label2 = new JLabel("待查询详情的编号:");
label4 =new JLabel("");
label4.setFont(new Font("宋体",Font.PLAIN,15));
field =new JTextField();
buttonOfchaxun=new JButton("查询");
buttonOfchaxun.addActionListener(this);
label3 = new JLabel("消费类别:");
Clabel =new JComboBox();
Clabel.addItem("全部");
Clabel.addItem("日用品");
Clabel.addItem("厨房用品");
Clabel.addItem("电子产品");
Clabel.addItem("工资收入");
Clabel.addItem("炒股收入");
Clabel.addItem("其他");
a =new Object[50][6];
table = new JTable(a, name);//组件的创建
table.setEnabled(false);
JScrollPane scrollPane = new JScrollPane(table);
box1 = Box.createVerticalBox();
box1.add(Box.createVerticalStrut(10));
box1.add(buttonOfzhichu);
box1.add(Box.createVerticalStrut(15));
box1.add(buttonOfshouru);
box1.add(Box.createVerticalStrut(15));
box1.add(label3);
box1.add(Box.createVerticalStrut(5));
box1.add(Clabel);
box1.add(Box.createVerticalStrut(5));
box1.add(buttonOfchaxun);
box1.add(label2);
box1.add(Box.createVerticalStrut(5));
box1.add(field);
box1.add(Box.createVerticalStrut(5));
box1.add(buttonOfXiangXi);
box1.add(Box.createVerticalStrut(5));
box1.add(buttonOfheji);
box1.add(Box.createVerticalStrut(5));
box1.add(label4);
box1.add(Box.createVerticalStrut(20));
box1.add(buttonOfLogout);
box2 = Box.createHorizontalBox();
box2.add(Box.createHorizontalStrut(10));
box2.add(box1);
jPanel4 = new JPanel();
jPanel5 = new JPanel();
jPanel4.setLayout(new BorderLayout());
jPanel4.add(box2,BorderLayout.NORTH);
jPanel5.setLayout(new BorderLayout());
jPanel5.add(label1,BorderLayout.NORTH);
jPanel5.add(scrollPane,BorderLayout.CENTER);
this.setLayout(new BorderLayout());
add(jPanel5,BorderLayout.EAST);
add(jPanel4,BorderLayout.WEST);
xinXiLiuLan();
}
public void connDB() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager.getConnection(DbUtil.dbUrlString, DbUtil.dbUser, DbUtil.dbpassword);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeDB()
{
try {
stmt.close();
con.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void xinXiLiuLan()
{
this.connDB();
int i=0;
try {
stmt = con.createStatement();
String sql = "select * from familydata ";
rs = stmt.executeQuery(sql);
while(i<50) {
a[i][0]=" ";
a[i][1]=" ";
a[i][2]=" ";
a[i][3]=" ";
a[i][4]=" ";
a[i][5]=" ";
i++;
}
i=0;
while(rs.next())
{
String id = rs.getString("id");
String way = rs.getString("way");
String classfiy = rs.getString("classfiy");
String money = rs.getString("money");
String flag = rs.getString("flag");
String user= rs.getString("user");
a[i][0]=id;
a[i][1]=way;
a[i][2]=classfiy;
a[i][3]=money;
a[i][4]=flag;
a[i][5]=user;
i++;
}
this.closeDB();
repaint();
} catch (SQLException e2) {
e2.printStackTrace();
}
this.closeDB();
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if(source==buttonOfzhichu) {
this.dispose();
new Luru(true);
}
else if(source==buttonOfshouru) {
this.dispose();
new Luru(false);
}
else if(source == buttonOfXiangXi)
{
this.dispose();
new Xiangxi(field.getText());
}
else if(source==buttonOfchaxun) {
this.connDB();
String classify=(String)Clabel.getSelectedItem();
String sql;
if(classify.equalsIgnoreCase("全部")) {
xinXiLiuLan();
}
else {
try {
int i=0;
stmt = con.createStatement();
sql = "select * from familydata where classfiy='"+classify+"'";
rs = stmt.executeQuery(sql);
while(i<50) {
a[i][0]=" ";
a[i][1]=" ";
a[i][2]=" ";
a[i][3]=" ";
a[i][4]=" ";
a[i][5]=" ";
i++;
}
i=0;
while(rs.next())
{
String id = rs.getString("id");
String way = rs.getString("way");
String classfiy = rs.getString("classfiy");
String money = rs.getString("money");
String flag = rs.getString("flag");
String user= rs.getString("user");
a[i][0]=id;
a[i][1]=way;
a[i][2]=classfiy;
a[i][3]=money;
a[i][4]=flag;
a[i][5]=user;
i++;
}
this.closeDB();
repaint();
} catch (SQLException e2) {
e2.printStackTrace();
}
this.closeDB();
}
}
else if(source == buttonOfheji) {
int sum=0;
String sums="null";
this.connDB();
try {
stmt = con.createStatement();
String sql= "select * from familydata ";
rs = stmt.executeQuery(sql);
while(rs.next())
{
String money =rs.getString("money");
String flag=rs.getString("flag");
int m=Integer.parseInt(money);
if(flag.equalsIgnoreCase("支出")) {
sum=sum-m;
}else if(flag.equalsIgnoreCase("收入")) {
sum=sum+m;
}
}
this.closeDB();
repaint();
} catch (SQLException e1) {
e1.printStackTrace();
}
this.closeDB();
sums=String.valueOf(sum);
label4.setText(sums);
}
else if(source == buttonOfLogout) {
this.dispose();
new Login();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
这是一个家庭理财系统!!!!支持收入和支出 统计总金额java.zip
共17个文件
class:7个
java:7个
project:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 182 浏览量
2023-08-11
15:04:09
上传
评论
收藏 30KB ZIP 举报
温馨提示
这是一个家庭理财系统!!!!支持收入和支出 统计总金额java.zip
资源推荐
资源详情
资源评论
收起资源包目录
这是一个家庭理财系统!!!!支持收入和支出 统计总金额java.zip (17个子文件)
A
familymoneymanage
.classpath 489B
.settings
org.eclipse.jdt.core.prefs 642B
src
Index
Zhuce.java 4KB
Login.java 4KB
StartMain.java 131B
Util
DbUtil.java 253B
yonghu
Xiangxi.java 4KB
Luru.java 6KB
zhumain.java 8KB
bin
Index
StartMain.class 450B
Login.class 5KB
Zhuce.class 5KB
Util
DbUtil.class 556B
yonghu
Xiangxi.class 5KB
zhumain.class 8KB
Luru.class 6KB
.project 393B
共 17 条
- 1
资源评论
处处清欢
- 粉丝: 154
- 资源: 2504
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功