diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..ac36ca9
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/.project b/.project
new file mode 100644
index 0000000..29e3584
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ hutibill
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..bb35fa0
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/img/backup.png b/img/backup.png
new file mode 100644
index 0000000..1d9ff70
Binary files /dev/null and b/img/backup.png differ
diff --git a/img/category1.png b/img/category1.png
new file mode 100644
index 0000000..85af0c7
Binary files /dev/null and b/img/category1.png differ
diff --git a/img/category2.png b/img/category2.png
new file mode 100644
index 0000000..d5e9000
Binary files /dev/null and b/img/category2.png differ
diff --git a/img/config.png b/img/config.png
new file mode 100644
index 0000000..fb3beed
Binary files /dev/null and b/img/config.png differ
diff --git a/img/home.png b/img/home.png
new file mode 100644
index 0000000..e45744f
Binary files /dev/null and b/img/home.png differ
diff --git a/img/record.png b/img/record.png
new file mode 100644
index 0000000..6ea3054
Binary files /dev/null and b/img/record.png differ
diff --git a/img/report.png b/img/report.png
new file mode 100644
index 0000000..8d5a2be
Binary files /dev/null and b/img/report.png differ
diff --git a/img/restore.png b/img/restore.png
new file mode 100644
index 0000000..1a8b3b3
Binary files /dev/null and b/img/restore.png differ
diff --git a/libs/chart.jar b/libs/chart.jar
new file mode 100644
index 0000000..c0bfbf6
Binary files /dev/null and b/libs/chart.jar differ
diff --git a/libs/liquidlnf.jar b/libs/liquidlnf.jar
new file mode 100644
index 0000000..8049772
Binary files /dev/null and b/libs/liquidlnf.jar differ
diff --git a/libs/mysql-connector-java-5.0.8-bin.jar b/libs/mysql-connector-java-5.0.8-bin.jar
new file mode 100644
index 0000000..0170c3e
Binary files /dev/null and b/libs/mysql-connector-java-5.0.8-bin.jar differ
diff --git a/libs/swingx-core-1.6.2.jar b/libs/swingx-core-1.6.2.jar
new file mode 100644
index 0000000..6ec2699
Binary files /dev/null and b/libs/swingx-core-1.6.2.jar differ
diff --git a/src/dao/CategoryDAO.java b/src/dao/CategoryDAO.java
new file mode 100644
index 0000000..e32b4ad
--- /dev/null
+++ b/src/dao/CategoryDAO.java
@@ -0,0 +1,137 @@
+package dao;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import entity.Category;
+import util.DBUtil;
+
+public class CategoryDAO {
+
+ public int getTotal() {
+ int total = 0;
+ try (Connection c = DBUtil.getConnection();Statement s = c.createStatement();){
+ String sql = "select count(*) from category";
+ ResultSet rs = s.executeQuery(sql);
+ while(rs.next()){
+ total = rs.getInt(1);
+ }
+ } catch (SQLException e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ return total;
+}
+
+
+ public void add(Category category) {
+
+ String sql = "insert into category values(null,?)";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setString(1, category.name);
+
+ ps.execute();
+
+ ResultSet rs = ps.getGeneratedKeys();
+ if (rs.next()) {
+ int id = rs.getInt(1);
+ category.id = id;
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public void update(Category category) {
+
+ String sql = "update category set name= ? where id = ?";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setString(1, category.name);
+ ps.setInt(2, category.id);
+
+ ps.execute();
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+
+ }
+
+ public void delete(int id) {
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "delete from category where id = " + id;
+
+ s.execute(sql);
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public Category get(int id) {
+ Category category = null;
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "select * from category where id = " + id;
+
+ ResultSet rs = s.executeQuery(sql);
+
+ if (rs.next()) {
+ category = new Category();
+ String name = rs.getString(2);
+ category.name = name;
+ category.id = id;
+ }
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return category;
+ }
+
+ public List list() {
+ return list(0, Short.MAX_VALUE);
+ }
+
+ public List list(int start, int count) {
+ List categorys = new ArrayList();
+
+ String sql = "select * from category order by id desc limit ?,? ";
+
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setInt(1, start);
+ ps.setInt(2, count);
+
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next()) {
+ Category category = new Category();
+ int id = rs.getInt(1);
+ String name = rs.getString(2);
+ category.id = id;
+ category.name = name;
+ categorys.add(category);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return categorys;
+ }
+
+}
\ No newline at end of file
diff --git a/src/dao/ConfigDAO.java b/src/dao/ConfigDAO.java
new file mode 100644
index 0000000..700357a
--- /dev/null
+++ b/src/dao/ConfigDAO.java
@@ -0,0 +1,171 @@
+package dao;
+
+import java.sql.Connection;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import entity.Config;
+import util.DBUtil;
+
+public class ConfigDAO {
+
+ public int getTotal() {
+ int total = 0;
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "select count(*) from config";
+
+ ResultSet rs = s.executeQuery(sql);
+ while (rs.next()) {
+ total = rs.getInt(1);
+ }
+
+ System.out.println("total:" + total);
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return total;
+ }
+
+ public void add(Config config) {
+
+ String sql = "insert into config values(null,?,?)";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+ ps.setString(1, config.key);
+ ps.setString(2, config.value);
+ ps.execute();
+ ResultSet rs = ps.getGeneratedKeys();
+ if (rs.next()) {
+ int id = rs.getInt(1);
+ config.id = id;
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public void update(Config config) {
+
+ String sql = "update config set key_= ?, value=? where id = ?";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setString(1, config.key);
+ ps.setString(2, config.value);
+ ps.setInt(3, config.id);
+
+ ps.execute();
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+
+ }
+
+ public void delete(int id) {
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "delete from config where id = " + id;
+
+ s.execute(sql);
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public Config get(int id) {
+ Config config = null;
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "select * from config where id = " + id;
+
+ ResultSet rs = s.executeQuery(sql);
+
+ if (rs.next()) {
+ config = new Config();
+ String key = rs.getString("key_");
+ String value = rs.getString("value");
+ config.key = key;
+ config.value = value;
+ config.id = id;
+ }
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return config;
+ }
+
+ public List list() {
+ return list(0, Short.MAX_VALUE);
+ }
+
+ public List list(int start, int count) {
+ List configs = new ArrayList();
+
+ String sql = "select * from config order by id desc limit ?,? ";
+
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setInt(1, start);
+ ps.setInt(2, count);
+
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next()) {
+ Config config = new Config();
+ int id = rs.getInt(1);
+ String key = rs.getString("key_");
+ String value = rs.getString("value");
+ config.id = id;
+ config.key = key;
+ config.value = value;
+ configs.add(config);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return configs;
+ }
+
+ public Config getByKey(String key) {
+ Config config = null;
+ String sql = "select * from config where key_ = ?" ;
+ try (Connection c = DBUtil.getConnection();
+ PreparedStatement ps = c.prepareStatement(sql);
+ ) {
+
+ ps.setString(1, key);
+ ResultSet rs =ps.executeQuery();
+
+ if (rs.next()) {
+ config = new Config();
+ int id = rs.getInt("id");
+ String value = rs.getString("value");
+ config.key = key;
+ config.value = value;
+ config.id = id;
+ }
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return config;
+ }
+
+}
\ No newline at end of file
diff --git a/src/dao/RecordDAO.java b/src/dao/RecordDAO.java
new file mode 100644
index 0000000..f0612cb
--- /dev/null
+++ b/src/dao/RecordDAO.java
@@ -0,0 +1,265 @@
+package dao;
+
+import java.sql.Connection;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import entity.Record;
+import util.DBUtil;
+import util.DateUtil;
+
+public class RecordDAO {
+
+ public int getTotal() {
+ int total = 0;
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "select count(*) from record";
+
+ ResultSet rs = s.executeQuery(sql);
+ while (rs.next()) {
+ total = rs.getInt(1);
+ }
+
+ System.out.println("total:" + total);
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return total;
+ }
+
+ public void add(Record record) {
+
+ String sql = "insert into record values(null,?,?,?,?)";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+ ps.setInt(1, record.spend);
+ ps.setInt(2, record.cid);
+ ps.setString(3, record.comment);
+ ps.setDate(4, DateUtil.util2sql(record.date));
+
+ ps.execute();
+
+ ResultSet rs = ps.getGeneratedKeys();
+ if (rs.next()) {
+ int id = rs.getInt(1);
+ record.id = id;
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public void update(Record record) {
+
+ String sql = "update record set spend= ?, cid= ?, comment =?, date = ? where id = ?";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setInt(1, record.spend);
+ ps.setInt(2, record.cid);
+ ps.setString(3, record.comment);
+ ps.setDate(4, DateUtil.util2sql(record.date));
+ ps.setInt(5, record.id);
+
+ ps.execute();
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+
+ }
+
+ public void delete(int id) {
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "delete from record where id = " + id;
+
+ s.execute(sql);
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public Record get(int id) {
+ Record record = null;
+
+ try (Connection c = DBUtil.getConnection(); Statement s = c.createStatement();) {
+
+ String sql = "select * from record where id = " + id;
+
+ ResultSet rs = s.executeQuery(sql);
+
+ if (rs.next()) {
+ record = new Record();
+ int spend = rs.getInt("spend");
+ int cid = rs.getInt("cid");
+ String comment = rs.getString("comment");
+ Date date = rs.getDate("date");
+
+ record.spend=spend;
+ record.cid=cid;
+ record.comment=comment;
+ record.date=date;
+ record.id = id;
+ }
+
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return record;
+ }
+
+ public List list() {
+ return list(0, Short.MAX_VALUE);
+ }
+
+ public List list(int start, int count) {
+ List records = new ArrayList();
+
+ String sql = "select * from record order by id desc limit ?,? ";
+
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setInt(1, start);
+ ps.setInt(2, count);
+
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next()) {
+ Record record = new Record();
+ int id = rs.getInt("id");
+ int spend = rs.getInt("spend");
+ int cid = rs.getInt("cid");
+
+ String comment = rs.getString("comment");
+ Date date = rs.getDate("date");
+
+ record.spend=spend;
+ record.cid=cid;
+ record.comment=comment;
+ record.date=date;
+ record.id = id;
+ records.add(record);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return records;
+ }
+
+ public List list(int cid) {
+ List records = new ArrayList();
+
+ String sql = "select * from record where cid = ?";
+
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+
+ ps.setInt(1, cid);
+
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next()) {
+ Record record = new Record();
+ int id = rs.getInt("id");
+ int spend = rs.getInt("spend");
+
+ String comment = rs.getString("comment");
+ Date date = rs.getDate("date");
+
+ record.spend=spend;
+ record.cid=cid;
+ record.comment=comment;
+ record.date=date;
+ record.id = id;
+ records.add(record);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return records;
+ }
+
+ public List listToday(){
+ return list(DateUtil.today());
+ }
+
+ public List list(Date day) {
+ List records = new ArrayList();
+ String sql = "select * from record where date =?";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+ ps.setDate(1, DateUtil.util2sql(day));
+
+ ResultSet rs = ps.executeQuery();
+ while (rs.next()) {
+ Record record = new Record();
+ int id = rs.getInt("id");
+ int cid = rs.getInt("cid");
+ int spend = rs.getInt("spend");
+
+ String comment = rs.getString("comment");
+ Date date = rs.getDate("date");
+
+ record.spend=spend;
+ record.cid=cid;
+ record.comment=comment;
+ record.date=date;
+ record.id = id;
+ records.add(record);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return records;
+ }
+
+ public List listThisMonth(){
+ return list(DateUtil.monthBegin(),DateUtil.monthEnd());
+ }
+
+ public List list(Date start, Date end) {
+ List records = new ArrayList();
+ String sql = "select * from record where date >=? and date <= ?";
+ try (Connection c = DBUtil.getConnection(); PreparedStatement ps = c.prepareStatement(sql);) {
+ ps.setDate(1, DateUtil.util2sql(start));
+ ps.setDate(2, DateUtil.util2sql(end));
+ ResultSet rs = ps.executeQuery();
+ while (rs.next()) {
+ Record record = new Record();
+ int id = rs.getInt("id");
+ int cid = rs.getInt("cid");
+ int spend = rs.getInt("spend");
+
+ String comment = rs.getString("comment");
+ Date date = rs.getDate("date");
+
+ record.spend=spend;
+ record.cid=cid;
+ record.comment=comment;
+ record.date=date;
+ record.id = id;
+ records.add(record);
+ }
+ } catch (SQLException e) {
+
+ e.printStackTrace();
+ }
+ return records;
+ }
+
+}
\ No newline at end of file
diff --git a/src/entity/Category.java b/src/entity/Category.java
new file mode 100644
index 0000000..27fb552
--- /dev/null
+++ b/src/entity/Category.java
@@ -0,0 +1,31 @@
+package entity;
+
+public class Category {
+ public int id;
+ public String name;
+
+ public int recordNumber;
+
+ public int getRecordNumber() {
+ return recordNumber;
+ }
+ public void setRecordNumber(int recordNumber) {
+ this.recordNumber = recordNumber;
+ }
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String toString(){
+ return name;
+ }
+}
\ No newline at end of file
diff --git a/src/entity/Config.java b/src/entity/Config.java
new file mode 100644
index 0000000..a319c02
--- /dev/null
+++ b/src/entity/Config.java
@@ -0,0 +1,27 @@
+package entity;
+
+public class Config {
+
+ public int id;
+ public String key;
+ public String value;
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public String getKey() {
+ return key;
+ }
+ public void setKey(String key) {
+ this.key = key;
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
\ No newline at end of file
diff --git a/src/entity/Record.java b/src/entity/Record.java
new file mode 100644
index 0000000..e201b4c
--- /dev/null
+++ b/src/entity/Record.java
@@ -0,0 +1,43 @@
+package entity;
+
+import java.util.Date;
+
+public class Record {
+ public int spend;
+ public int id;
+ public int cid;
+ public String comment;
+ public Date date;
+
+ public int getId() {
+ return id;
+ }
+ public void setId(int id) {
+ this.id = id;
+ }
+ public int getCid() {
+ return cid;
+ }
+ public void setCid(int cid) {
+ this.cid = cid;
+ }
+ public String getComment() {
+ return comment;
+ }
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+ public Date getDate() {
+ return date;
+ }
+ public void setDate(Date date) {
+ this.date = date;
+ }
+ public int getSpend() {
+ return spend;
+ }
+ public void setSpend(int spend) {
+ this.spend = spend;
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/frame/MainFrame.java b/src/gui/frame/MainFrame.java
new file mode 100644
index 0000000..76752ec
--- /dev/null
+++ b/src/gui/frame/MainFrame.java
@@ -0,0 +1,24 @@
+package gui.frame;
+
+import javax.swing.JFrame;
+
+import gui.panel.MainPanel;
+import util.GUIUtil;
+
+public class MainFrame extends JFrame{
+ public static MainFrame instance = new MainFrame();
+
+ private MainFrame(){
+ this.setSize(500,450);
+ this.setTitle("һͿ");
+ this.setContentPane(MainPanel.instance);
+ this.setLocationRelativeTo(null);
+ this.setResizable(false);
+ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+
+ public static void main(String[] args) {
+ instance.setVisible(true);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/listener/CategoryListener.java b/src/gui/listener/CategoryListener.java
new file mode 100644
index 0000000..ede6653
--- /dev/null
+++ b/src/gui/listener/CategoryListener.java
@@ -0,0 +1,54 @@
+package gui.listener;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+
+import entity.Category;
+import gui.panel.CategoryPanel;
+import service.CategoryService;
+
+public class CategoryListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ CategoryPanel p = CategoryPanel.instance;
+ JButton b =(JButton) e.getSource();
+ if(b == p.bAdd){
+ String name = JOptionPane.showInputDialog(null);
+ if(0 == name.length()){
+ JOptionPane.showMessageDialog(p, "ƲΪ");
+ return;
+ }
+ new CategoryService().add(name);
+ }
+
+ if(b == p.bEdit){
+ Category c = p.getSelectedCategory();
+ int id = c.id ;
+ String name = JOptionPane.showInputDialog("ķ",c.name);
+ if(0 == name.length()){
+ JOptionPane.showMessageDialog(p, "ƲΪ");
+ return;
+ }
+ new CategoryService().update(id, name);
+ }
+
+ if(b == p.bDelete){
+ Category c = p.getSelectedCategory();
+ if(0 != c.recordNumber){
+ JOptionPane.showMessageDialog(p, "Ѽ¼ڣɾ");
+ return;
+ }
+ if(JOptionPane.OK_OPTION!=JOptionPane.showConfirmDialog(p, "ȷҪɾ")){
+ return;}
+ int id = c.id;
+ new CategoryService().delete(id);
+ }
+ p.updateData();
+
+ }
+}
\ No newline at end of file
diff --git a/src/gui/listener/ConfigListener.java b/src/gui/listener/ConfigListener.java
new file mode 100644
index 0000000..8116929
--- /dev/null
+++ b/src/gui/listener/ConfigListener.java
@@ -0,0 +1,38 @@
+package gui.listener;
+
+import java.awt.event.ActionEvent;
+
+import java.awt.event.ActionListener;
+import java.io.File;
+
+import javax.swing.JOptionPane;
+
+import gui.panel.ConfigPanel;
+import service.ConfigService;
+import util.GUIUtil;
+
+public class ConfigListener implements ActionListener{
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ ConfigPanel p = ConfigPanel.instance;
+ if (!GUIUtil.checkEmpty(p.tfBudget, "Ԥ")) {
+ return;
+ }
+ String mysqlPath = p.tfMysqlPath.getText();
+ if(0!=mysqlPath.length()){
+ File commandFile = new File(mysqlPath,"bin/mysql.exe");
+ if(!commandFile.exists()){
+ JOptionPane.showMessageDialog(p, "·ȷ");
+ p.tfMysqlPath.grabFocus();
+ return;
+ }
+ }
+ ConfigService cs = new ConfigService();
+ cs.update(ConfigService.budget, p.tfBudget.getText());
+ cs.update(ConfigService.mysqlPath, mysqlPath);
+ JOptionPane.showMessageDialog(p, "ijɹ");
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/listener/RecordListener.java b/src/gui/listener/RecordListener.java
new file mode 100644
index 0000000..e865459
--- /dev/null
+++ b/src/gui/listener/RecordListener.java
@@ -0,0 +1,43 @@
+package gui.listener;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Date;
+
+import javax.swing.JOptionPane;
+
+import org.omg.CORBA.INTERNAL;
+
+import entity.Category;
+import gui.panel.CategoryPanel;
+import gui.panel.MainPanel;
+import gui.panel.RecordPanel;
+import gui.panel.SpendPanel;
+import service.CategoryService;
+import service.RecordService;
+import util.GUIUtil;
+
+public class RecordListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ RecordPanel p = RecordPanel.instance;
+ if(0 == p.cbModel.cs.size()){
+ JOptionPane.showMessageDialog(p, "ûзϢ");
+ MainPanel.instance.workingPanel.show(CategoryPanel.instance);
+ return;
+ }
+
+ if(!GUIUtil.checkZero(p.tfSpend, "ѽ")){
+ return;
+ }
+
+ int spend = Integer.parseInt(p.tfSpend.getText());
+ Category c = p.getSelectedCategory();
+ String comment = p.tfComment.getText();
+ Date date = p.datepick.getDate();
+ new RecordService().add(spend, c, comment, date);
+ MainPanel.instance.workingPanel.show(SpendPanel.instance);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/listener/ToolBarListener.java b/src/gui/listener/ToolBarListener.java
new file mode 100644
index 0000000..e6d5579
--- /dev/null
+++ b/src/gui/listener/ToolBarListener.java
@@ -0,0 +1,39 @@
+package gui.listener;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+
+import gui.panel.BackupPanel;
+import gui.panel.CategoryPanel;
+import gui.panel.ConfigPanel;
+import gui.panel.MainPanel;
+import gui.panel.RecordPanel;
+import gui.panel.RecoverPanel;
+import gui.panel.ReportPanel;
+import gui.panel.SpendPanel;
+
+public class ToolBarListener implements ActionListener {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // TODO Auto-generated method stub
+ MainPanel p = MainPanel.instance;
+ JButton b = (JButton) e.getSource();
+ if (b == p.bReport)
+ p.workingPanel.show(ReportPanel.instance);
+ if (b == p.bCategory)
+ p.workingPanel.show(CategoryPanel.instance);
+ if (b == p.bSpend)
+ p.workingPanel.show(SpendPanel.instance);
+ if (b == p.bRecord)
+ p.workingPanel.show(RecordPanel.instance);
+ if (b == p.bConfig)
+ p.workingPanel.show(ConfigPanel.instance);
+ if (b == p.bBackup)
+ p.workingPanel.show(BackupPanel.instance);
+ if (b == p.bRecover)
+ p.workingPanel.show(RecoverPanel.instance);
+ }
+}
diff --git a/src/gui/model/CategoryComboBoxModel.java b/src/gui/model/CategoryComboBoxModel.java
new file mode 100644
index 0000000..19b2f0f
--- /dev/null
+++ b/src/gui/model/CategoryComboBoxModel.java
@@ -0,0 +1,61 @@
+package gui.model;
+
+import java.util.List;
+
+import javax.swing.ComboBoxModel;
+import javax.swing.event.ListDataListener;
+
+import entity.Category;
+import service.CategoryService;
+
+public class CategoryComboBoxModel implements ComboBoxModel{
+
+ public List cs = new CategoryService().list();
+
+ public Category c;
+
+ public CategoryComboBoxModel(){
+ if(!cs.isEmpty())
+ c=cs.get(0);
+ }
+
+ @Override
+ public int getSize() {
+ // TODO Auto-generated method stub
+
+ return cs.size();
+ }
+
+ @Override
+ public Category getElementAt(int index) {
+ // TODO Auto-generated method stub
+ return cs.get(index);
+ }
+
+ @Override
+ public void addListDataListener(ListDataListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeListDataListener(ListDataListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setSelectedItem(Object anItem) {
+ c = (Category) anItem;
+ }
+
+ @Override
+ public Object getSelectedItem() {
+ if(!cs.isEmpty())
+ return c;
+ else
+ return null;
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/model/CategoryTableModel.java b/src/gui/model/CategoryTableModel.java
new file mode 100644
index 0000000..641ebdb
--- /dev/null
+++ b/src/gui/model/CategoryTableModel.java
@@ -0,0 +1,77 @@
+package gui.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.event.TableModelListener;
+import javax.swing.table.TableModel;
+
+import entity.Category;
+import entity.Config;
+
+public class CategoryTableModel implements TableModel{
+
+ String[] columnNames = new String[]{"","Ѵ"};
+ public List cs = new ArrayList<>();
+
+ @Override
+ public int getRowCount() {
+ // TODO Auto-generated method stub
+ return cs.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ // TODO Auto-generated method stub
+ return columnNames.length;
+ }
+
+ @Override
+ public String getColumnName(int columnIndex) {
+ // TODO Auto-generated method stub
+ return columnNames[columnIndex];
+ }
+
+ @Override
+ public Class> getColumnClass(int columnIndex) {
+ // TODO Auto-generated method stub
+ return String.class;
+ }
+
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ Category h = cs.get(rowIndex);
+ if (0 == columnIndex) {
+ return h.name;
+ }
+ if(1 == columnIndex){
+ return h.recordNumber;
+ }
+ return null;
+ }
+
+ @Override
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void addTableModelListener(TableModelListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeTableModelListener(TableModelListener l) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/page/SpendPage.java b/src/gui/page/SpendPage.java
new file mode 100644
index 0000000..b03ec90
--- /dev/null
+++ b/src/gui/page/SpendPage.java
@@ -0,0 +1,40 @@
+package gui.page;
+
+public class SpendPage {
+ //
+ public String monthSpend;
+ //
+ public String todaySpend;
+ //վ
+ public String avgSpendPerDay;
+ //ʣ
+ public String monthAvailable;
+ //վ
+ public String dayAvgAvailable;
+ //ĩ
+ public String monthLeftDay;
+ //ʹñ
+ public int usagePercentage;
+ //Ƿ֧
+ public boolean isOverSpend = false;
+
+ public SpendPage(int monthSpend, int todaySpend, int avgSpendPerDay, int monthAvailable, int dayAvgAvailable,
+ int monthLeftDay, int usagePercentage) {
+ this.monthSpend = "" + monthSpend;
+ this.todaySpend = "" + todaySpend;
+ this.avgSpendPerDay = "" + avgSpendPerDay;
+ if (monthAvailable < 0)
+ isOverSpend = true;
+
+ if (!isOverSpend) {
+ this.monthAvailable = "" + monthAvailable;
+ this.dayAvgAvailable = "" + dayAvgAvailable;
+ } else {
+ this.monthAvailable = "֧" + (0 - monthAvailable);
+ this.dayAvgAvailable = "0";
+ }
+
+ this.monthLeftDay = monthLeftDay + "";
+ this.usagePercentage = usagePercentage;
+ }
+}
\ No newline at end of file
diff --git a/src/gui/panel/BackupPanel.java b/src/gui/panel/BackupPanel.java
new file mode 100644
index 0000000..4aff495
--- /dev/null
+++ b/src/gui/panel/BackupPanel.java
@@ -0,0 +1,26 @@
+package gui.panel;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class BackupPanel extends JPanel {
+ static{
+ GUIUtil.useLNF();
+ }
+
+ public static BackupPanel instance = new BackupPanel();
+ JButton bBackup =new JButton("");
+
+ public BackupPanel() {
+ GUIUtil.setColor(ColorUtil.blueColor, bBackup);
+ this.add(bBackup);
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(BackupPanel.instance);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/panel/CategoryPanel.java b/src/gui/panel/CategoryPanel.java
new file mode 100644
index 0000000..0b4c329
--- /dev/null
+++ b/src/gui/panel/CategoryPanel.java
@@ -0,0 +1,76 @@
+package gui.panel;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+
+import entity.Category;
+import gui.listener.CategoryListener;
+import gui.model.CategoryTableModel;
+import service.CategoryService;
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class CategoryPanel extends WorkingPanel{
+ static{
+ GUIUtil.useLNF();
+ }
+ public static CategoryPanel instance = new CategoryPanel();
+
+ public JButton bAdd = new JButton("");
+ public JButton bEdit = new JButton("༭");
+ public JButton bDelete = new JButton("ɾ");
+ String columNames[] = new String[]{"","Ѵ"};
+
+ public CategoryTableModel ctm = new CategoryTableModel();
+ public JTable t =new JTable(ctm);
+
+ public CategoryPanel() {
+ GUIUtil.setColor(ColorUtil.blueColor, bAdd,bEdit,bDelete);
+ JScrollPane sp =new JScrollPane(t);
+ JPanel pSubmit = new JPanel();
+ pSubmit.add(bAdd);
+ pSubmit.add(bEdit);
+ pSubmit.add(bDelete);
+
+ this.setLayout(new BorderLayout());
+ this.add(sp,BorderLayout.CENTER);
+ this.add(pSubmit,BorderLayout.SOUTH);
+
+ addListener();
+ }
+ public void addListener() {
+ CategoryListener listener = new CategoryListener();
+ bAdd.addActionListener(listener);
+ bEdit.addActionListener(listener);
+ bDelete.addActionListener(listener);
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(CategoryPanel.instance);
+ }
+
+
+ public Category getSelectedCategory() {
+ int index = t.getSelectedRow();
+ return ctm.cs.get(index);
+ }
+
+ public void updateData() {
+ ctm.cs = new CategoryService().list();
+ t.updateUI();
+ t.getSelectionModel().setSelectionInterval(0, 0);
+
+ if(0==ctm.cs.size()){
+ bEdit.setEnabled(false);
+ bDelete.setEnabled(false);
+ }
+ else{
+ bEdit.setEnabled(true);
+ bDelete.setEnabled(true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/gui/panel/ConfigPanel.java b/src/gui/panel/ConfigPanel.java
new file mode 100644
index 0000000..c249362
--- /dev/null
+++ b/src/gui/panel/ConfigPanel.java
@@ -0,0 +1,68 @@
+package gui.panel;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import gui.listener.ConfigListener;
+import service.ConfigService;
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class ConfigPanel extends WorkingPanel {
+ static{
+ GUIUtil.useLNF();
+ }
+ public static ConfigPanel instance = new ConfigPanel();
+
+ JLabel lBudget = new JLabel("Ԥ()");
+ public JTextField tfBudget = new JTextField("0");
+
+ JLabel lMysql = new JLabel("MysqlװĿ¼");
+ public JTextField tfMysqlPath = new JTextField("");
+
+ JButton bSubmit = new JButton("");
+
+ public ConfigPanel() {
+ GUIUtil.setColor(ColorUtil.grayColor, lBudget,lMysql);
+ GUIUtil.setColor(ColorUtil.blueColor, bSubmit);
+
+ JPanel pInput =new JPanel();
+ JPanel pSubmit = new JPanel();
+ int gap =40;
+ pInput.setLayout(new GridLayout(4,1,gap,gap));
+
+ pInput.add(lBudget);
+ pInput.add(tfBudget);
+ pInput.add(lMysql);
+ pInput.add(tfMysqlPath);
+ this.setLayout(new BorderLayout());
+ this.add(pInput,BorderLayout.NORTH);
+
+ pSubmit.add(bSubmit);
+ this.add(pSubmit,BorderLayout.CENTER);
+
+ addListener();
+ }
+ public void addListener(){
+ ConfigListener l = new ConfigListener();
+ bSubmit.addActionListener(l);
+ }
+ public static void main(String[] args) {
+ GUIUtil.showPanel(ConfigPanel.instance);
+ }
+ @Override
+ public void updateData() {
+ // TODO Auto-generated method stub
+ String budget = new ConfigService().get(ConfigService.budget);
+ String mysqlpath = new ConfigService().get(ConfigService.mysqlPath);
+ tfBudget.setText(budget);
+ tfMysqlPath.setText(mysqlpath);
+ tfBudget.grabFocus();
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/panel/MainPanel.java b/src/gui/panel/MainPanel.java
new file mode 100644
index 0000000..c160353
--- /dev/null
+++ b/src/gui/panel/MainPanel.java
@@ -0,0 +1,73 @@
+package gui.panel;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JToolBar;
+
+import gui.listener.ToolBarListener;
+import util.CenterPanel;
+import util.GUIUtil;
+
+public class MainPanel extends JPanel {
+ static {
+ GUIUtil.useLNF();
+ }
+
+ public static MainPanel instance = new MainPanel();
+ public JToolBar tb = new JToolBar();
+ public JButton bSpend = new JButton();
+ public JButton bRecord = new JButton();
+ public JButton bCategory = new JButton();
+ public JButton bReport = new JButton();
+ public JButton bConfig = new JButton();
+ public JButton bBackup = new JButton();
+ public JButton bRecover = new JButton();
+
+ public CenterPanel workingPanel;
+
+ private MainPanel() {
+
+ GUIUtil.setImageIcon(bSpend, "home.png", "һ");
+ GUIUtil.setImageIcon(bRecord, "record.png", "һ");
+ GUIUtil.setImageIcon(bCategory, "category2.png", "ѷ");
+ GUIUtil.setImageIcon(bReport, "report.png", "ѱ");
+ GUIUtil.setImageIcon(bConfig, "config.png", "");
+ GUIUtil.setImageIcon(bBackup, "backup.png", "");
+ GUIUtil.setImageIcon(bRecover, "restore.png", "ָ");
+
+ tb.add(bSpend);
+ tb.add(bRecord);
+ tb.add(bCategory);
+ tb.add(bReport);
+ tb.add(bConfig);
+ tb.add(bBackup);
+ tb.add(bRecover);
+ tb.setFloatable(false);
+
+ workingPanel = new CenterPanel(0.8);
+
+ setLayout(new BorderLayout());
+ add(tb, BorderLayout.NORTH);
+ add(workingPanel, BorderLayout.CENTER);
+
+ addListener();
+ }
+ private void addListener() {
+ ToolBarListener listener = new ToolBarListener();
+
+ bSpend.addActionListener(listener);
+ bRecord.addActionListener(listener);
+ bCategory.addActionListener(listener);
+ bReport.addActionListener(listener);
+ bConfig.addActionListener(listener);
+ bBackup.addActionListener(listener);
+ bRecover.addActionListener(listener);
+
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(MainPanel.instance, 1);
+ }
+}
\ No newline at end of file
diff --git a/src/gui/panel/RecordPanel.java b/src/gui/panel/RecordPanel.java
new file mode 100644
index 0000000..cb644a8
--- /dev/null
+++ b/src/gui/panel/RecordPanel.java
@@ -0,0 +1,99 @@
+package gui.panel;
+
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.util.Date;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import org.jdesktop.swingx.JXDatePicker;
+
+import entity.Category;
+import gui.listener.RecordListener;
+import gui.model.CategoryComboBoxModel;
+import service.CategoryService;
+import service.RecordService;
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class RecordPanel extends WorkingPanel {
+ static{
+ GUIUtil.useLNF();
+ }
+ public static RecordPanel instance = new RecordPanel();
+
+ JLabel lSpend = new JLabel("()");
+ JLabel lCategory = new JLabel("");
+ JLabel lComment = new JLabel("ע");
+ JLabel lDate = new JLabel("");
+
+ public JTextField tfSpend = new JTextField("0");
+
+ public CategoryComboBoxModel cbModel = new CategoryComboBoxModel();
+ public JComboBox cbCategory = new JComboBox<>(cbModel);
+ public JTextField tfComment = new JTextField();
+ public JXDatePicker datepick = new JXDatePicker(new Date());
+
+ JButton bSubmit = new JButton("һ");
+
+ public RecordPanel() {
+ GUIUtil.setColor(ColorUtil.grayColor, lSpend,lCategory,lComment,lDate);
+ GUIUtil.setColor(ColorUtil.blueColor, bSubmit);
+ JPanel pInput =new JPanel();
+ JPanel pSubmit = new JPanel();
+ int gap = 40;
+ pInput.setLayout(new GridLayout(4,2,gap,gap));
+
+ pInput.add(lSpend);
+ pInput.add(tfSpend);
+ pInput.add(lCategory);
+ pInput.add(cbCategory);
+ pInput.add(lComment);
+ pInput.add(tfComment);
+ pInput.add(lDate);
+ pInput.add(datepick);
+
+ pSubmit.add(bSubmit);
+
+ this.setLayout(new BorderLayout());
+ this.add(pInput,BorderLayout.NORTH);
+ this.add(pSubmit,BorderLayout.CENTER);
+
+ addListener();
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(RecordPanel.instance);
+ }
+
+ public Category getSelectedCategory(){
+ return (Category) cbCategory.getSelectedItem();
+ }
+
+ @Override
+ public void updateData() {
+ cbModel.cs = new CategoryService().list();
+ cbCategory.updateUI();
+ resetInput();
+ tfSpend.grabFocus();
+ }
+
+ public void resetInput(){
+ tfSpend.setText("0");
+ tfComment.setText("");
+ if(0!=cbModel.cs.size())
+ cbCategory.setSelectedIndex(0);
+ datepick.setDate(new Date());
+ }
+
+ @Override
+ public void addListener() {
+ RecordListener listener = new RecordListener();
+ bSubmit.addActionListener(listener);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/panel/RecoverPanel.java b/src/gui/panel/RecoverPanel.java
new file mode 100644
index 0000000..5e39a63
--- /dev/null
+++ b/src/gui/panel/RecoverPanel.java
@@ -0,0 +1,28 @@
+package gui.panel;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class RecoverPanel extends JPanel {
+ static{
+ GUIUtil.useLNF();
+ }
+ public static RecoverPanel instance = new RecoverPanel();
+
+ JButton bRecover =new JButton("ָ");
+
+ public RecoverPanel() {
+
+ GUIUtil.setColor(ColorUtil.blueColor, bRecover);
+ this.add(bRecover);
+
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(RecoverPanel.instance);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/panel/ReportPanel.java b/src/gui/panel/ReportPanel.java
new file mode 100644
index 0000000..63fe82a
--- /dev/null
+++ b/src/gui/panel/ReportPanel.java
@@ -0,0 +1,34 @@
+package gui.panel;
+
+import java.awt.BorderLayout;
+import java.awt.Image;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import util.ChartUtil;
+import util.GUIUtil;
+
+public class ReportPanel extends JPanel {
+ static {
+ GUIUtil.useLNF();
+ }
+
+ public static ReportPanel instance = new ReportPanel();
+
+ public JLabel l = new JLabel();
+
+ public ReportPanel() {
+ this.setLayout(new BorderLayout());
+ Image i =ChartUtil.getImage(400, 300);
+ ImageIcon icon= new ImageIcon(i);
+ l.setIcon(icon);
+ this.add(l);
+ }
+
+ public static void main(String[] args) {
+ GUIUtil.showPanel(ReportPanel.instance);
+ }
+
+}
\ No newline at end of file
diff --git a/src/gui/panel/SpendPanel.java b/src/gui/panel/SpendPanel.java
new file mode 100644
index 0000000..7121746
--- /dev/null
+++ b/src/gui/panel/SpendPanel.java
@@ -0,0 +1,131 @@
+package gui.panel;
+
+import static util.GUIUtil.setColor;
+import static util.GUIUtil.showPanel;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.GridLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import gui.page.SpendPage;
+import service.SpendService;
+import util.CircleProgressBar;
+import util.ColorUtil;
+
+public class SpendPanel extends WorkingPanel {
+ public static SpendPanel instance = new SpendPanel();
+
+ JLabel lMonthSpend = new JLabel("");
+ JLabel lTodaySpend = new JLabel("");
+ JLabel lAvgSpendPerDay = new JLabel("վ");
+ JLabel lMonthLeft = new JLabel("ʣ");
+ JLabel lDayAvgAvailable = new JLabel("վ");
+ JLabel lMonthLeftDay = new JLabel("ĩ");
+
+ JLabel vMonthSpend = new JLabel("2300");
+ JLabel vTodaySpend = new JLabel("25");
+ JLabel vAvgSpendPerDay = new JLabel("120");
+ JLabel vMonthAvailable = new JLabel("2084");
+ JLabel vDayAvgAvailable = new JLabel("389");
+ JLabel vMonthLeftDay = new JLabel("15");
+
+ CircleProgressBar bar;
+
+ public SpendPanel() {
+ this.setLayout(new BorderLayout());
+ bar = new CircleProgressBar();
+ bar.setBackgroundColor(ColorUtil.blueColor);
+
+ setColor(ColorUtil.grayColor, lMonthSpend, lTodaySpend, lAvgSpendPerDay, lMonthLeft, lDayAvgAvailable,
+ lMonthLeftDay, vAvgSpendPerDay, vMonthAvailable, vDayAvgAvailable, vMonthLeftDay);
+ setColor(ColorUtil.blueColor, vMonthSpend, vTodaySpend);
+
+ vMonthSpend.setFont(new Font("ź", Font.BOLD, 23));
+ vTodaySpend.setFont(new Font("ź", Font.BOLD, 23));
+
+ this.add(center(), BorderLayout.CENTER);
+ this.add(south(), BorderLayout.SOUTH);
+
+ }
+
+ private JPanel center() {
+ JPanel p = new JPanel();
+ p.setLayout(new BorderLayout());
+ p.add(west(), BorderLayout.WEST);
+ p.add(east());
+
+ return p;
+ }
+
+ private Component east() {
+
+ return bar;
+ }
+
+ private Component west() {
+ JPanel p = new JPanel();
+ p.setLayout(new GridLayout(4, 1));
+ p.add(lMonthSpend);
+ p.add(vMonthSpend);
+ p.add(lTodaySpend);
+ p.add(vTodaySpend);
+ return p;
+ }
+
+ private JPanel south() {
+ JPanel p = new JPanel();
+ p.setLayout(new GridLayout(2, 4));
+
+ p.add(lAvgSpendPerDay);
+ p.add(lMonthLeft);
+ p.add(lDayAvgAvailable);
+ p.add(lMonthLeftDay);
+ p.add(vAvgSpendPerDay);
+ p.add(vMonthAvailable);
+ p.add(vDayAvgAvailable);
+ p.add(vMonthLeftDay);
+
+ return p;
+ }
+
+ public static void main(String[] args) {
+ showPanel(SpendPanel.instance);
+ }
+
+ @Override
+ public void updateData() {
+ SpendPage spend = new SpendService().getSpendPage();
+ vMonthSpend.setText(spend.monthSpend);
+ vTodaySpend.setText(spend.todaySpend);
+ vAvgSpendPerDay.setText(spend.avgSpendPerDay);
+ vMonthAvailable.setText(spend.monthAvailable);
+ vDayAvgAvailable.setText(spend.dayAvgAvailable);
+ vMonthLeftDay.setText(spend.monthLeftDay);
+
+ bar.setProgress(spend.usagePercentage);
+ if (spend.isOverSpend) {
+ vMonthAvailable.setForeground(ColorUtil.warningColor);
+ vMonthSpend.setForeground(ColorUtil.warningColor);
+ vTodaySpend.setForeground(ColorUtil.warningColor);
+
+ } else {
+ vMonthAvailable.setForeground(ColorUtil.grayColor);
+ vMonthSpend.setForeground(ColorUtil.blueColor);
+ vTodaySpend.setForeground(ColorUtil.blueColor);
+ }
+ bar.setForegroundColor(ColorUtil.getByPercentage(spend.usagePercentage));
+ addListener();
+
+ }
+
+ @Override
+ public void addListener() {
+ // TODO Auto-generated method stub
+
+ }
+}
\ No newline at end of file
diff --git a/src/gui/panel/WorkingPanel.java b/src/gui/panel/WorkingPanel.java
new file mode 100644
index 0000000..a2e4483
--- /dev/null
+++ b/src/gui/panel/WorkingPanel.java
@@ -0,0 +1,8 @@
+package gui.panel;
+
+import javax.swing.JPanel;
+
+public abstract class WorkingPanel extends JPanel{
+ public abstract void updateData();
+ public abstract void addListener();
+}
\ No newline at end of file
diff --git a/src/service/CategoryService.java b/src/service/CategoryService.java
new file mode 100644
index 0000000..98e060e
--- /dev/null
+++ b/src/service/CategoryService.java
@@ -0,0 +1,45 @@
+package service;
+
+import java.util.Collections;
+import java.util.List;
+
+import dao.CategoryDAO;
+import dao.RecordDAO;
+import entity.Category;
+import entity.Record;
+
+public class CategoryService {
+
+ CategoryDAO categoryDao = new CategoryDAO();
+ RecordDAO recordDao = new RecordDAO();
+
+ public List list(){
+ List cs = categoryDao.list();
+ for(Category c:cs){
+ List rs = recordDao.list(c.id);
+ c.recordNumber = rs.size();
+ }
+ Collections.sort(cs,(c1,c2)->c2.recordNumber-c1.recordNumber);
+
+ return cs;
+ }
+
+ public void add(String name) {
+ Category c = new Category();
+ c.setName(name);
+ categoryDao.add(c);
+ }
+
+
+ public void update(int id,String name){
+ Category c = new Category();
+ c.setId(id);
+ c.setName(name);
+ categoryDao.update(c);
+ }
+
+ public void delete(int id) {
+ categoryDao.delete(id);
+
+ }
+}
\ No newline at end of file
diff --git a/src/service/ConfigService.java b/src/service/ConfigService.java
new file mode 100644
index 0000000..107d3e7
--- /dev/null
+++ b/src/service/ConfigService.java
@@ -0,0 +1,49 @@
+package service;
+
+import javax.naming.InitialContext;
+
+import dao.ConfigDAO;
+import entity.Config;
+
+public class ConfigService {
+ public static final String budget ="budget";
+ public static final String mysqlPath = "mysqlPath";
+ public static final String default_budget = "500";
+
+ static ConfigDAO dao = new ConfigDAO();
+ static{
+ init();
+ }
+
+ public static void init(){
+ init(budget,default_budget);
+ init(mysqlPath,"");
+ }
+
+ public static void init(String key,String value) {
+ Config config = dao.getByKey(key);
+ if (config == null) {
+ Config c = new Config();
+ c.setKey(key);
+ c.setValue(value);
+ dao.add(c);
+ }
+
+ }
+
+ public String get(String key){
+ Config config = dao.getByKey(key);
+ return config.getValue();
+ }
+
+ public void update(String key,String value){
+ Config config = dao.getByKey(key);
+ config.setValue(value);
+ dao.update(config);
+ }
+
+ public int getIntBudget() {
+ return Integer.parseInt(get(budget));
+ }
+
+}
\ No newline at end of file
diff --git a/src/service/RecordService.java b/src/service/RecordService.java
new file mode 100644
index 0000000..a18b4f9
--- /dev/null
+++ b/src/service/RecordService.java
@@ -0,0 +1,21 @@
+package service;
+
+import java.util.Date;
+import dao.RecordDAO;
+import entity.Category;
+import entity.Record;
+
+public class RecordService {
+ RecordDAO recordDAO = new RecordDAO();
+ public void add(int spend, Category c, String comment,Date date){
+ Record r = new Record();
+ r.spend = spend;
+ r.cid = c.id;
+ r.comment = comment;
+ r.date = date;
+ recordDAO.add(r);
+ }
+
+
+
+}
diff --git a/src/service/SpendService.java b/src/service/SpendService.java
new file mode 100644
index 0000000..bb8af91
--- /dev/null
+++ b/src/service/SpendService.java
@@ -0,0 +1,60 @@
+package service;
+
+import java.util.List;
+
+import dao.RecordDAO;
+import entity.Record;
+import gui.page.SpendPage;
+import util.DateUtil;
+
+public class SpendService {
+
+ public SpendPage getSpendPage() {
+ RecordDAO dao = new RecordDAO();
+ //
+ List thisMonthRecords = dao.listThisMonth();
+ //
+ List toDayRecords = dao.listToday();
+ //
+ int thisMonthTotalDay = DateUtil.thisMonthTotalDay();
+
+ int monthSpend = 0;
+ int todaySpend = 0;
+ int avgSpendPerDay = 0;
+ int monthAvailable = 0;
+ int dayAvgAvailable = 0;
+ int monthLeftDay = 0;
+ int usagePercentage = 0;
+
+ // Ԥ
+ int monthBudget = new ConfigService().getIntBudget();
+
+ // ͳƱ
+ for (Record record : thisMonthRecords) {
+ monthSpend += record.getSpend();
+ }
+
+ // ͳƽ
+ for (Record record : toDayRecords) {
+ todaySpend += record.getSpend();
+ }
+ // վ
+ avgSpendPerDay = monthSpend / thisMonthTotalDay;
+ // 㱾ʣ
+ monthAvailable = monthBudget - monthSpend;
+
+ // ĩ
+ monthLeftDay = DateUtil.thisMonthLeftDay();
+
+ // վ
+ dayAvgAvailable = monthAvailable / monthLeftDay;
+
+ // ʹñ
+ usagePercentage = monthSpend * 100 / monthBudget;
+
+ // ЩϢSpendPage
+
+ return new SpendPage(monthSpend, todaySpend, avgSpendPerDay, monthAvailable, dayAvgAvailable, monthLeftDay,
+ usagePercentage);
+ }
+}
\ No newline at end of file
diff --git a/src/startup/Bootstrap.java b/src/startup/Bootstrap.java
new file mode 100644
index 0000000..9a7b6ba
--- /dev/null
+++ b/src/startup/Bootstrap.java
@@ -0,0 +1,22 @@
+package startup;
+
+import javax.swing.SwingUtilities;
+
+import gui.frame.MainFrame;
+import gui.panel.MainPanel;
+import gui.panel.SpendPanel;
+import util.GUIUtil;
+
+public class Bootstrap {
+ public static void main(String[] args) throws Exception{
+ GUIUtil.useLNF();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ MainFrame.instance.setVisible(true);
+ MainPanel.instance.workingPanel.show(SpendPanel.instance);
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/test/Test.java b/src/test/Test.java
new file mode 100644
index 0000000..557e719
--- /dev/null
+++ b/src/test/Test.java
@@ -0,0 +1,61 @@
+package test;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+import util.CircleProgressBar;
+import util.ColorUtil;
+import util.GUIUtil;
+
+public class Test {
+ public static void main(String[] args) {
+ GUIUtil.useLNF();
+ //
+ JPanel p = new JPanel();
+ //
+ CircleProgressBar cpb = new CircleProgressBar();
+ cpb.setBackgroundColor(ColorUtil.blueColor);
+ cpb.setProgress(0);
+ //ť
+ JButton b = new JButton("");
+ //
+ p.setLayout(new BorderLayout());
+ p.add(cpb, BorderLayout.CENTER);
+ p.add(b, BorderLayout.SOUTH);
+ //ʾ
+ GUIUtil.showPanel(p);
+
+ //ťӼ
+ b.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ new SwingWorker() {
+
+ @Override
+ protected Object doInBackground() throws Exception {
+ for (int i = 0; i < 100; i++) {
+ cpb.setProgress(i + 1);
+ cpb.setForegroundColor(ColorUtil.getByPercentage(i + 1));
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ }.execute();
+
+ }
+ });
+
+ }
+}
\ No newline at end of file
diff --git a/src/util/CenterPanel.java b/src/util/CenterPanel.java
new file mode 100644
index 0000000..e1d1942
--- /dev/null
+++ b/src/util/CenterPanel.java
@@ -0,0 +1,71 @@
+package util;
+
+import java.awt.Component;
+
+import java.awt.Dimension;
+
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+import gui.panel.WorkingPanel;
+
+public class CenterPanel extends JPanel {
+
+ private double rate;//
+ private JComponent c; //ʾ
+ private boolean strech; //Ƿ
+
+ public CenterPanel(double rate,boolean strech) {
+ this.setLayout(null);
+ this.rate = rate;
+ this.strech = strech;
+ }
+
+ public CenterPanel(double rate) {
+ this(rate,true);
+ }
+
+ public void repaint() {
+ if (null != c) {
+ Dimension containerSize = this.getSize();
+ Dimension componentSize= c.getPreferredSize();
+
+ if(strech)
+ c.setSize((int) (containerSize.width * rate), (int) (containerSize.height * rate));
+ else
+ c.setSize(componentSize);
+
+ c.setLocation(containerSize.width / 2 - c.getSize().width / 2, containerSize.height / 2 - c.getSize().height / 2);
+ }
+ super.repaint();
+ }
+
+ public void show(JComponent p) {
+ this.c = p;
+ Component[] cs = getComponents();
+ for (Component c : cs) {
+ remove(c);
+ }
+ add(p);
+
+ if (p instanceof WorkingPanel)
+ ((WorkingPanel) p).updateData();
+ this.updateUI();
+ }
+
+ public static void main(String[] args) {
+ JFrame f = new JFrame();
+ f.setSize(200, 200);
+ f.setLocationRelativeTo(null);
+ CenterPanel cp = new CenterPanel(0.85,true);
+ f.setContentPane(cp);
+ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ f.setVisible(true);
+ JButton b =new JButton("abc");
+ cp.show(b);
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/util/ChartUtil.java b/src/util/ChartUtil.java
new file mode 100644
index 0000000..c6778a2
--- /dev/null
+++ b/src/util/ChartUtil.java
@@ -0,0 +1,109 @@
+package util;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Image;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import com.objectplanet.chart.BarChart;
+import com.objectplanet.chart.Chart;
+
+public class ChartUtil {
+
+ public static int max(double[] sampleValues) {
+ int max = 0;
+ for (double v : sampleValues) {
+ if (v > max)
+ max = (int) v;
+ }
+ return max;
+
+ }
+
+ private static String[] sampleLabels() {
+ String[] sampleLabels = new String[30];
+
+ for (int i = 0; i < sampleLabels.length; i++) {
+ if (0 == i % 5)
+ sampleLabels[i] = String.valueOf(i + 1 + "");
+ }
+ return sampleLabels;
+ }
+
+ public static Image getImage(int width, int height) {
+ // ģ
+ double[] sampleValues = sampleValues();
+ // ·ʾ
+ String[] sampleLabels = sampleLabels();
+ // еֵ
+ int max = max(sampleValues);
+
+ // ɫ
+ Color[] sampleColors = new Color[] { ColorUtil.blueColor };
+
+ // ״ͼ
+ BarChart chart = new BarChart();
+
+ //
+ chart.setSampleCount(sampleValues.length);
+ //
+ chart.setSampleValues(0, sampleValues);
+ //
+ chart.setSampleLabels(sampleLabels);
+ // ɫ
+ chart.setSampleColors(sampleColors);
+ // ȡֵΧ
+ chart.setRange(0, max * 1.2);
+ // ʾ
+ chart.setValueLinesOn(true);
+ // ʾ
+ chart.setSampleLabelsOn(true);
+ // ʾ·
+ chart.setSampleLabelStyle(Chart.BELOW);
+
+ // ֵ
+ chart.setFont("rangeLabelFont", new Font("Arial", Font.BOLD, 12));
+ // ʾͼ˵
+ chart.setLegendOn(true);
+ // ͼ˵
+ chart.setLegendPosition(Chart.LEFT);
+ // ͼ˵е
+ chart.setLegendLabels(new String[] { "ѱ" });
+ // ͼ˵
+ chart.setFont("legendFont", new Font("Dialog", Font.BOLD, 13));
+ // ·ֵ
+ chart.setFont("sampleLabelFont", new Font("Dialog", Font.BOLD, 13));
+ // ͼм䱳ɫ
+ chart.setChartBackground(Color.white);
+ // ͼ屳ɫ
+ chart.setBackground(ColorUtil.backgroundColor);
+ // ͼתΪImage
+ Image im = chart.getImage(width, height);
+ return im;
+ }
+
+ private static double[] sampleValues() {
+
+ double[] result = new double[30];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = (int) (Math.random() * 300);
+ }
+ return result;
+
+ }
+
+ public static void main(String[] args) {
+ JPanel p = new JPanel();
+ JLabel l = new JLabel();
+ Image img = ChartUtil.getImage(400, 300);
+ Icon icon = new ImageIcon(img);
+ l.setIcon(icon);
+ p.add(l);
+ GUIUtil.showPanel(p);
+ }
+
+}
\ No newline at end of file
diff --git a/src/util/CircleProgressBar.java b/src/util/CircleProgressBar.java
new file mode 100644
index 0000000..1ac8478
--- /dev/null
+++ b/src/util/CircleProgressBar.java
@@ -0,0 +1,108 @@
+package util;
+
+import java.awt.BasicStroke;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+public class CircleProgressBar extends JPanel {
+
+ private int minimumProgress;
+
+ private int maximumProgress;
+
+ private int progress;
+
+ private String progressText;
+
+ private Color backgroundColor;
+
+ private Color foregroundColor;
+
+ public CircleProgressBar() {
+ minimumProgress = 0;
+ maximumProgress = 100;
+ progressText = "0%";
+ }
+
+ public void paint(Graphics g) {
+ super.paint(g);
+ Graphics2D graphics2d = (Graphics2D) g;
+ //
+ graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ int x = 0;
+ int y = 0;
+ int width = 0;
+ int height = 0;
+ int fontSize = 0;
+ if (getWidth() >= getHeight()) {
+ x = (getWidth() - getHeight()) / 2 + 25;
+ y = 25;
+ width = getHeight() - 50;
+ height = getHeight() - 50;
+ fontSize = getWidth() / 8;
+ } else {
+ x = 25;
+ y = (getHeight() - getWidth()) / 2 + 25;
+ width = getWidth() - 50;
+ height = getWidth() - 50;
+ fontSize = getHeight() / 8;
+ }
+ graphics2d.setStroke(new BasicStroke(20.0f));
+ graphics2d.setColor(backgroundColor);
+ graphics2d.drawArc(x, y, width, height, 0, 360);
+ graphics2d.setColor(foregroundColor);
+ graphics2d.drawArc(x, y, width, height, 90,
+ -(int) (360 * ((progress * 1.0) / (maximumProgress - minimumProgress))));
+ graphics2d.setFont(new Font("", Font.BOLD, fontSize));
+ FontMetrics fontMetrics = graphics2d.getFontMetrics();
+ int digitalWidth = fontMetrics.stringWidth(progressText);
+ int digitalAscent = fontMetrics.getAscent();
+ graphics2d.setColor(foregroundColor);
+ graphics2d.drawString(progressText, getWidth() / 2 - digitalWidth / 2, getHeight() / 2 + digitalAscent / 2);
+ }
+
+ public int getProgress() {
+ return progress;
+ }
+
+ public void setProgress(int progress) {
+ if (progress >= minimumProgress && progress <= maximumProgress)
+ this.progress = progress;
+ if (progress > maximumProgress)
+ this.progress = maximumProgress;
+
+ this.progressText = String.valueOf(progress + "%");
+
+ this.repaint();
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ this.repaint();
+ }
+
+ public Color getForegroundColor() {
+ return foregroundColor;
+ }
+
+ public void setForegroundColor(Color foregroundColor) {
+ this.foregroundColor = foregroundColor;
+ this.repaint();
+ }
+
+}
\ No newline at end of file
diff --git a/src/util/ColorUtil.java b/src/util/ColorUtil.java
new file mode 100644
index 0000000..2a2c77d
--- /dev/null
+++ b/src/util/ColorUtil.java
@@ -0,0 +1,23 @@
+package util;
+
+import java.awt.Color;
+
+public class ColorUtil {
+ public static Color blueColor = Color.decode("#3399FF");
+ public static Color grayColor = Color.decode("#999999");
+ public static Color backgroundColor = Color.decode("#eeeeee");
+ public static Color warningColor = Color.decode("#FF3333");
+
+ public static Color getByPercentage(int per) {
+ if (per > 100)
+ per = 100;
+ int r = 51;
+ int g = 255;
+ int b = 51;
+ float rate = per / 100f;
+ r = (int) ((255 - 51) * rate + 51);
+ g = 255 - r + 51;
+ Color color = new Color(r, g, b);
+ return color;
+ }
+}
\ No newline at end of file
diff --git a/src/util/DBUtil.java b/src/util/DBUtil.java
new file mode 100644
index 0000000..8f6c389
--- /dev/null
+++ b/src/util/DBUtil.java
@@ -0,0 +1,26 @@
+package util;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class DBUtil {
+ static String ip = "127.0.0.1";
+ static int port = 3306;
+ static String database = "hutubill";
+ static String encoding = "UTF-8";
+ static String loginName = "root";
+ static String password = "admin";
+ static{
+ try {
+ Class.forName("com.mysql.jdbc.Driver");
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static Connection getConnection() throws SQLException {
+ String url = String.format("jdbc:mysql://%s:%d/%s?characterEncoding=%s", ip, port, database, encoding);
+ return DriverManager.getConnection(url, loginName, password);
+ }
+}
\ No newline at end of file
diff --git a/src/util/DateUtil.java b/src/util/DateUtil.java
new file mode 100644
index 0000000..5e5bead
--- /dev/null
+++ b/src/util/DateUtil.java
@@ -0,0 +1,92 @@
+package util;
+
+import java.util.Calendar;
+import java.util.Date;
+
+public class DateUtil {
+ static long millisecondsOfOneDay = 1000*60*60*24;
+
+ public static java.sql.Date util2sql(java.util.Date d){
+ return new java.sql.Date(d.getTime());
+ }
+
+ /**
+ * ȡ죬Ұʱ֣ͺ붼0. Ϊͨڿؼȡڣûʱͺġ
+ * @return
+ */
+ public static Date today(){
+ Calendar c = Calendar.getInstance();
+ c.setTime(new Date());
+ c.set(Calendar.HOUR,0);
+ c.set(Calendar.MINUTE,0);
+ c.set(Calendar.SECOND,0);
+ return c.getTime();
+
+ }
+
+ /**
+ * ȡ³ʹCalendarȡµһ졣 ͳһϢʱ鿴µݣʵǴݿȥѴӱµһ쵽һݲٽмͳƣҪһȡµһķ
+ * @return
+ */
+
+ public static Date monthBegin() {
+ Calendar c = Calendar.getInstance();
+ c.setTime(new Date());
+ c.set(Calendar.DATE, 1);
+
+ c.set(Calendar.HOUR_OF_DAY, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ return c.getTime();
+
+ }
+
+ /**
+ * ȡĩ
+ * @return
+ */
+ public static Date monthEnd() {
+ Calendar c = Calendar.getInstance();
+ c.setTime(new Date());
+ c.set(Calendar.HOUR, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+
+ c.set(Calendar.DATE, 1);
+ c.add(Calendar.MONDAY, 1);
+ c.add(Calendar.DATE, -1);
+ return c.getTime();
+ }
+
+ /**
+ * ȡһж
+ * @return
+ */
+ public static int thisMonthTotalDay(){
+
+ long lastDayMilliSeconds = monthEnd().getTime();
+ long firstDayMilliSeconds = monthBegin().getTime();
+
+ return (int) ((lastDayMilliSeconds-firstDayMilliSeconds)/millisecondsOfOneDay) +1;
+ }
+
+ /**
+ *ȡ»ʣ
+ * @return
+ */
+
+ public static int thisMonthLeftDay(){
+ long lastDayMilliSeconds = monthEnd().getTime();
+ long toDayMilliSeconds = today().getTime();
+ return (int) ((lastDayMilliSeconds-toDayMilliSeconds)/millisecondsOfOneDay) +1;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(DateUtil.today());
+ System.out.println(DateUtil.monthBegin());
+ System.out.println(DateUtil.monthEnd());
+ System.out.println(thisMonthLeftDay());
+ System.out.println(thisMonthTotalDay());
+ }
+}
\ No newline at end of file
diff --git a/src/util/GUIUtil.java b/src/util/GUIUtil.java
new file mode 100644
index 0000000..6179153
--- /dev/null
+++ b/src/util/GUIUtil.java
@@ -0,0 +1,105 @@
+package util;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.io.File;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+public class GUIUtil {
+ private static String imageFolder = "E:/eclipse/workspace/hutibill/img";
+
+ public static void setImageIcon(JButton b, String fileName, String tip) {
+ ImageIcon i = new ImageIcon(new File(imageFolder, fileName).getAbsolutePath());
+ b.setIcon(i);
+ b.setPreferredSize(new Dimension(61, 81));
+ b.setToolTipText(tip);
+ b.setVerticalTextPosition(JButton.BOTTOM);
+ b.setHorizontalTextPosition(JButton.CENTER);
+ b.setText(tip);
+ }
+
+ public static void setColor(Color color, JComponent... cs) {
+ for (JComponent c : cs) {
+ c.setForeground(color);
+ }
+ }
+
+ /**
+ *
+ * @param p
+ * @param strechRate 1ʾĻ
+ */
+ public static void showPanel(JPanel p,double strechRate) {
+ GUIUtil.useLNF();
+ JFrame f = new JFrame();
+ f.setSize(500, 500);
+ f.setLocationRelativeTo(null);
+ CenterPanel cp = new CenterPanel(strechRate);
+ f.setContentPane(cp);
+ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ f.setVisible(true);
+ cp.show(p);
+ }
+
+ public static void showPanel(JPanel p) {
+ showPanel(p,0.85);
+ }
+
+ public static boolean checkNumber(JTextField tf, String input) {
+ if (!checkEmpty(tf, input))
+ return false;
+ String text = tf.getText().trim();
+ try {
+ Integer.parseInt(text);
+ return true;
+ } catch (NumberFormatException e1) {
+ JOptionPane.showMessageDialog(null, input + " Ҫ");
+ tf.grabFocus();
+ return false;
+ }
+ }
+
+ public static boolean checkZero(JTextField tf, String input) {
+ if (!checkNumber(tf, input))
+ return false;
+ String text = tf.getText().trim();
+
+ if (0 == Integer.parseInt(text)) {
+ JOptionPane.showMessageDialog(null, input + " Ϊ");
+ tf.grabFocus();
+ return false;
+ }
+ return true;
+ }
+
+ public static boolean checkEmpty(JTextField tf, String input) {
+ String text = tf.getText().trim();
+ if (0 == text.length()) {
+ JOptionPane.showMessageDialog(null, input + " Ϊ");
+ tf.grabFocus();
+ return false;
+ }
+ return true;
+
+ }
+
+ public static int getInt(JTextField tf) {
+ return Integer.parseInt(tf.getText());
+ }
+
+ public static void useLNF() {
+ try {
+ javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file