import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JButton;
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 java.sql.DriverManager;
public class Money_in_Dialog extends Dialog {
private java.sql.Connection conn = null;
private JTextField jtf1 = null;
private JTextField jtf2 = null;
private JTextField jtf3 = null;
private JTextField jtf4 = null;
private JTextField jtf5 = null;
private JTextField jtf6 = null;
private float s1 = 0;
private DefaultTableModel mm;
public Money_in_Dialog(Frame frame, String title, boolean modal) {
super(frame, title, modal);
jbInit();
}
private void jbInit() {
JLabel jl1 = new JLabel("收入合计");
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "zw");
Statement stmt1 = conn.createStatement();
ResultSet rs1 = stmt1.executeQuery("select * from inmoneys");
while (rs1.next()) {
float s = Float.valueOf(rs1.getString(3));
s1 = s + s1;
}
} catch (SQLException e1) {
e1.printStackTrace();
}
String s = String.valueOf(s1);
JLabel jl2 = new JLabel(s);
//
JLabel jl3 = new JLabel("收入日期");
jtf1 = new JTextField();
//
JLabel jl5 = new JLabel("收入来源");
jtf2 = new JTextField();
//
JLabel jl7 = new JLabel("金额");
jtf3 = new JTextField();
jtf3.setHorizontalAlignment(jtf3.RIGHT);
//
JLabel jl9 = new JLabel("存放方式");
jtf4 = new JTextField();
//
JLabel jl11 = new JLabel("收入者");
jtf5 = new JTextField();
JLabel jl12 = new JLabel("备注");
jtf6 = new JTextField();
//
JButton b1 = new JButton("重新输入");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jtf1.setText(null);
jtf2.setText(null);
jtf3.setText(null);
jtf4.setText(null);
jtf5.setText(null);
jtf6.setText(null);
}
});
JTable jb = new JTable();
JPanel jp1 = new JPanel();
JPanel jp3 = new JPanel();
JPanel jp4 = new JPanel();
JPanel jp5 = new JPanel();
JPanel jp6 = new JPanel();
JPanel jp7 = new JPanel();
jp1.add(jl1);
jp1.add(jl2);
jp3.setLayout(new BorderLayout());
jp5.add(jl3);
jp5.add(jtf1);
jp5.add(jl5);
jp5.add(jtf2);
jp5.add(jl7);
jp5.add(jtf3);
jp5.setLayout(new GridLayout(1, 6));
jp3.add(jp5, BorderLayout.NORTH);
jp6.add(jl9);
jp6.add(jtf4);
jp6.add(jl11);
jp6.add(jtf5);
jp6.add(jl12);
jp6.add(jtf6);
jp6.setLayout(new GridLayout(1, 6));
jp3.add(jp6, BorderLayout.CENTER);
String[] col = { "日期", "收入来源", "金额", "存放方式", "收入者", "备注" };
mm = new DefaultTableModel(col, 0);
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "zw");
Statement stmt2 = conn.createStatement();
ResultSet rs2 = stmt2.executeQuery("select * from inmoneys");
while (rs2.next()) {
String date = rs2.getString(1);
String source = rs2.getString(2);
String money = rs2.getString(3);
String place = rs2.getString(4);
String iner = rs2.getString(5);
String remark = rs2.getString(6);
String[] zw = { date, source, money, place, iner, remark };
mm.addRow(zw);
}
} catch (SQLException e1) {
e1.printStackTrace();
}
JButton b2 = new JButton("保存");
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "zw");
Statement stmt1 = conn.createStatement();
String s = "insert into inmoneys values" + "('"
+ jtf1.getText() + "','" + jtf2.getText() + "','"
+ jtf3.getText() + "','" + jtf4.getText() + "','"
+ jtf5.getText() + "','" + jtf6.getText() + "');";
System.out.println(s);
boolean rs1 = stmt1.execute(s);
if (!rs1) {
jtf1.setText(null);
jtf2.setText(null);
jtf3.setText(null);
jtf4.setText(null);
jtf5.setText(null);
jtf6.setText(null);
Statement stmt2 = conn.createStatement();
ResultSet rs2 = stmt2
.executeQuery("select * from inmoneys");
while (rs2.next()) {
String[] col = { "日期", "收入来源", "金额", "存放方式", "收入者",
"备注" };
mm = new DefaultTableModel(col, 0);
String date = rs2.getString(1);
String source = rs2.getString(2);
String money = rs2.getString(3);
String place = rs2.getString(4);
String iner = rs2.getString(5);
String remark = rs2.getString(6);
String[] zw = { date, source, money, place, iner,
remark };
mm.addRow(zw);
}
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
JButton b3 = new JButton("删除");
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test", "root", "zw");
Statement stmt1 = conn.createStatement();
String s = "delete from inmoneys where date='"
+ jtf1.getText() + "';";
boolean rs1 = stmt1.execute(s);
if(rs1){
System.out.println("123");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
JButton b4 = new JButton("返回");
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// setVisible(false);
dispose();
}
});
jp7.add(b1);
jp7.add(b2);
jp7.add(b3);
jp7.add(b4);
jp3.add(jp7, BorderLayout.SOUTH);
JScrollPane jscrollpane = new JScrollPane(jb);
jp4.setLayout(new BorderLayout());
jp4.add(jp1, BorderLayout.NORTH);
jp4.add(jscrollpane, BorderLayout.CENTER);
jp4.add(jp3, BorderLayout.SOUTH);
jb.setModel(mm);
this.add(jp4);
this.setSize(700, 400);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
mysql+MyEclipse编写的家庭理财工具代码,课程设计专用
共44个文件
class:33个
java:9个
project:1个
4星 · 超过85%的资源 需积分: 10 41 下载量 67 浏览量
2010-01-27
16:12:29
上传
评论 2
收藏 50KB RAR 举报
温馨提示
本人编写的mysql+MyEclipse编写的家庭理财工具代码,课程设计专用。因为我也是学生编写不易,所以多要点分,呵呵
资源推荐
资源详情
资源评论
收起资源包目录
MyFirstproject.rar (44个子文件)
MyFirstproject
.project 390B
bin
User_Dialog1$2.class 2KB
Family.class 1KB
Money_Dialog$1.class 1KB
User_Dialog1$1.class 651B
Money_in_Dialog$3.class 2KB
Zw_Dialog.class 1KB
Zichang_Dialog$4.class 663B
Money_Dialog$3.class 651B
MainFrame$2.class 1KB
Money_Dialog.class 3KB
User_JTable.class 3KB
Money_in_Dialog$1.class 972B
Money_Dialog$2.class 1KB
Money_in_Dialog$4.class 669B
Money_out_Dialog$2.class 3KB
Zichang_Dialog.class 6KB
Money_out_Dialog$3.class 2KB
Money_out_Dialog.class 6KB
Zichang_Dialog$2.class 3KB
Money_out_Dialog$1.class 943B
Money_in_Dialog.class 6KB
User_Dialog1$3.class 679B
MainFrame$5.class 656B
MainFrame$1.class 1KB
Money_in_Dialog$2.class 3KB
MainFrame$3.class 1KB
MainFrame.class 2KB
Money_out_Dialog$4.class 675B
Zichang_Dialog$1.class 929B
Zw_Dialog$1.class 633B
User_Dialog1.class 3KB
Zichang_Dialog$3.class 2KB
MainFrame$4.class 1KB
src
MainFrame.java 4KB
Money_in_Dialog.java 7KB
Zichang_Dialog.java 6KB
User_JTable.java 2KB
User_Dialog1.java 3KB
Family.java 745B
Money_out_Dialog.java 6KB
Zw_Dialog.java 980B
Money_Dialog.java 3KB
.classpath 365B
共 44 条
- 1
资源评论
- 那年泼泼2014-06-28这些资料很有参考价值,界面简洁。
- AlanWZT2018-05-21表的结构都不给我们,叫我们如何在自己的电脑上运行哦,
zwxiaole
- 粉丝: 20
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功