zoukankan      html  css  js  c++  java
  • 213.家庭账务管理信息系统

    开发环境:win10_x64

    开发语言:Java(v1.8) 和 sql(v5.7)

    开发工具:eclipse 和 MySQL

    运行环境:win10_x64

    //Moneymanager.java
    package cn.bjxy.zander;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.text.*;
    
    public class Moneymanager  implements  ActionListener {
        public static Moneymanager m = new Moneymanager();
        JFrame f = new JFrame("Family Money Manager");
        String[] Names={"序号","收入","支出","时间","备注"};
        JTable table=new JTable(new Show().playerInfo,Names);
        JScrollPane s=new JScrollPane(table);
        static JPanel p = new JPanel();
        static JButton bt1 = new JButton("修改密码");
        static JButton bt2 = new JButton("修改数据");
        static JButton bt3 = new JButton("删除数据");
    //    static JButton bt8 = new JButton("hi数据");
        static JButton bt4 = new JButton("财务统计");
        static JButton bt5 = new JButton("添加记录");
        static JButton bt6 = new JButton("帮助");
        static JButton bt7 = new JButton("数据清空");
        static JLabel lb1 = new JLabel("收入         元"); 
        static JLabel lb2 = new JLabel("支出         元");
        static JLabel lb3 = new JLabel("时间");
        static JLabel lb4 = new JLabel("备注");
        static JLabel lb5 = new JLabel("家庭财务管理信息系统");
        static JLabel lb6 = new JLabel("0");
        static JTextField txt1 = new JTextField("0");
        static JTextField txt2 = new JTextField("0");
        static JTextField txt3 = new JTextField(m.gettime());
        static JTextField txt4 = new JTextField();
        public static String[][]a = new String[10000][5];
        public static Integer[][]b = new Integer[10000][5];
        
        public void MoneymanagerWindow (){
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setBounds(100, 50, 849, 600); //主窗口大小
            f.setLayout(null);f.setResizable(false);
            p.add(s);f.add(p);
            table.setPreferredScrollableViewportSize(new Dimension(770,370));
            table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            p.setBounds(20,105,800,410);
            bt1.setBounds(5,5,200,40);f.add(bt1);bt1.addActionListener(this);
            bt2.setBounds(215,5,200,40);f.add(bt2);bt2.addActionListener(this);
            bt3.setBounds(425,5,200,40);f.add(bt3);bt3.addActionListener(this);
            bt4.setBounds(635,5,200,40);f.add(bt4);bt4.addActionListener(this);
            bt5.setBounds(720,60,100,40);f.add(bt5);bt5.addActionListener(this);
            bt6.setBounds(40,520,200,40);f.add(bt6);bt6.addActionListener(this);
            bt7.setBounds(260,520,200,40);f.add(bt7);bt7.addActionListener(this);
            lb1.setBounds(20,60,200,40);f.add(lb1);
            lb1.setFont(new Font("Serif",Font.BOLD,18));
            lb2.setBounds(170,60,200,40);f.add(lb2);
            lb2.setFont(new Font("Serif",Font.BOLD,18));
            lb3.setBounds(315,60,200,40);f.add(lb3);
            lb3.setFont(new Font("Serif",Font.BOLD,18));
            lb4.setBounds(470,60,200,40);f.add(lb4);
            lb4.setFont(new Font("Serif",Font.BOLD,18));
            lb5.setBounds(560,520,250,40);f.add(lb5);
            lb5.setFont(new Font("Serif",Font.BOLD,24));
            //lb6.setBounds(710,522,250,40);f.add(lb6);
            //lb6.setFont(new Font("Serif",Font.BOLD,18));
            txt1.setBounds(60,70,55,20);f.add(txt1);
            txt2.setBounds(210,70,55,20);f.add(txt2);
            txt3.setBounds(355,70,100,20);f.add(txt3);
            txt4.setBounds(510,70,200,20);f.add(txt4);
            f.setVisible(true);
        }
        
        
        public void actionPerformed(ActionEvent   e){
            if(e.getSource()==bt1){
                new Changepw();
            }
            else if(e.getSource()==bt2){
                new ChangeData();
                //new Show().getplayerInfo();
                m.f5();//table.updateUI(); 
            }else if(e.getSource()==bt3){
                new DelData();
                 //table.updateUI();
            }else if(e.getSource()==bt4){
                new Tongji();
                //table.updateUI();
            }else if(e.getSource()==bt5){
                new AddData();
                m.f5();
                //table.setValueAt("hhhh", 3, 2);
                //m.f5();
              } else if(e.getSource()==bt6){
                new Help();
                  //m.f5();
            }else if(e.getSource()==bt7){
                String j=JOptionPane.showInputDialog("请输入密码:");
                if(new GetOldPW().getpw().equals(j)){
                    new FormartData();
                }else
                    JOptionPane.showMessageDialog(null,"密码错误!清空失败!");    
            }
        }
         
        
               
        
        public  String gettime(){
            Date now = new Date(); 
            DateFormat d = DateFormat.getDateInstance(); 
            return d.format(now);     
        }
        
        public void f5(){
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
        //    String url = "jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true";
            try{
                Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接数据库
                Statement s = c.createStatement();                       
                ResultSet r=s.executeQuery("select * from Moneymanager");//将查询得到的结果集给rs
                int i=0;
                while(r.next()){
                   Moneymanager.m.table.setValueAt(String.valueOf(i+1), i, 0);
                   Moneymanager.m.table.setValueAt(String.valueOf((r.getInt("收入"))), i, 1);
                   Moneymanager.m.table.setValueAt(String.valueOf((r.getInt("支出"))), i, 2);
                   Moneymanager.m.table.setValueAt(r.getString("时间"), i, 3);
                   Moneymanager.m.table.setValueAt(r.getString("备注"), i, 4);
                   i++;
                }
            c.close();s.close();
           }catch(SQLException e1){
               e1.getStackTrace();
           }     
        }
      
       public static void main(String args[]){
         new Enter();
       }
    }
    //Enter.java
    package cn.bjxy.zander;
    import  java.awt.event.*;
    import javax.swing.*;
    //登录————————————————————————————————————————————————————————————————————
     public class Enter extends JFrame   implements ActionListener {
        
        private static final long serialVersionUID = 1L;
        static JFrame f1 = new JFrame("家庭财务信息管理系统");
        static JButton bt1 = new JButton("登入");
        static JButton bt2 = new JButton("退出");
        static JLabel lb1 = new JLabel("请输入密码: ");
        static JPasswordField pw = new JPasswordField();
         
        public Enter (){
               f1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
               f1.setLayout(null);
               f1.setBounds(300, 200, 300, 200);
               f1.setResizable(false);
               bt1.setBounds(60, 100, 60, 30);
               bt2.setBounds(160, 100, 60, 30);           
               lb1.setBounds(60, 30, 200, 20);
               pw.setBounds(60, 60, 150, 25);
               f1.add(bt1);bt1.addActionListener(this);
               f1.add(bt2);    bt2.addActionListener(this);
               f1.add(lb1);
               f1.add(pw);    
               f1.setVisible(true);
        }
        
    public void actionPerformed(ActionEvent e){
        String a,b;
        a=new String (pw.getPassword());
        b=new GetOldPW().getpw();
        if(e.getSource()==bt1){            
            if(a.equals(b)){
                f1.setVisible(false);
                Moneymanager.m.MoneymanagerWindow(); 
            }else{ 
                pw.cut();//错误声音提示
                JOptionPane.showMessageDialog(null,"密码错误,请重新输入密码 !      ");
            }
                                           
        }else if(e.getSource()==bt2){
            System.exit(0);
        }
    }
    /*
        public static void main(String[] args) {
        //      new Enter();
        }*/
    
    }
    //GetOldPW.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    //读取旧密码
    class GetOldPW {
        String oldpw;
        public String getpw(){
            try{
                Class.forName("com.mysql.jdbc.Driver");//安装驱动
            }catch(java.lang.ClassNotFoundException e){
                System.out.println("forname: " + e.getMessage());
            }
            try{
                Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8");//连接数据库
                Statement s = c.createStatement();
                ResultSet rs = s.executeQuery("select * from pw");
                while(rs.next()){
                    oldpw=rs.getString("password");
                }
                s.close();
                c.close();
            }catch(SQLException e){
                System.out.println("SQLException: "+ e.getMessage());    
            }
            return oldpw;
        }
    }
    //Changepw.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import javax.swing.*;
    //更改密码
     class Changepw {
        
        String j =    JOptionPane.showInputDialog("请输入原密码:");
        
        public  Changepw(){
            if(j.equals(new GetOldPW().getpw())){
                String k =    JOptionPane.showInputDialog("请输入新密码:");
                String l =    JOptionPane.showInputDialog("请确认新密码:");
                if(l.equals(k)){
                    try{
                        Class.forName("com.mysql.jdbc.Driver");//安装驱动
                    }catch(java.lang.ClassNotFoundException e){
                        System.out.println("forname: " + e.getMessage());
                    }
                    
                    try{
                        Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8");//连接数据库
                        PreparedStatement s = c.prepareStatement("UPDATE pw set password=?");
                        s.setString(1, l);
                        s.executeUpdate();
                        s.close();
                        c.close();
                        JOptionPane.showMessageDialog(null,"密码修改成功!!");
                    }catch(SQLException e){
                        System.out.println("SQLException: "+ e.getMessage());    
                    }
                }else
                    JOptionPane.showMessageDialog(null,"两次输入密码不同!修改失败!");    
            }else
                JOptionPane.showMessageDialog(null,"密码错误!修改失败!  ");
            }
        
        /*public static void main(String[] args) {
              //new Changepw()
        }*/
    }
     
     
    //AddData.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement; 
    import javax.swing.JOptionPane;
    
     //添加数据
    
    class AddData{
    
    public  AddData(){
        //____________________________________________________________
        try{
            Class.forName("com.mysql.jdbc.Driver");//安装驱动
        }catch(java.lang.ClassNotFoundException e){
            System.out.println("forname: " + e.getMessage());
        }
        
        
        try{
            Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8");//连接数据库
            Statement s = c.createStatement();
            Integer shouru = Integer.valueOf(Moneymanager.txt1.getText());
            Integer zhichu = Integer.valueOf(Moneymanager.txt2.getText());
            String shijian = Moneymanager.txt3.getText();
            String beizhu = Moneymanager.txt4.getText();
            //非法输入 收入支出均为零
            if(!shouru.equals(0)||!zhichu.equals(0)){
                new Show().getplayerInfo();
                //insert into Moneymanager new value
                s.executeUpdate("insert into Moneymanager(序号,收入,支出,时间,备注)  values('"+(new Show().xuhao+1)+"','"+shouru+"','"+zhichu+"','"+shijian+"','"+beizhu+" ')");//添加数据
                Moneymanager.txt1.setText("0");Moneymanager.txt2.setText("0");
                Moneymanager.txt4.setText(" ");
                }
            else
                JOptionPane.showMessageDialog(null,"请输入收入或支出 !   ");
            s.close();
            c.close();
        }catch(SQLException e){
            System.out.println("SQLException: "+ e.getMessage());    
        }
    }
    
    /*
        public static void main(String[] args){
            //new AddData();
        }*/
    }
        
    //ChangeData.java
    package cn.bjxy.zander;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.*;
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    //更改数据
     class ChangeData extends JFrame implements ActionListener{
        private static final long serialVersionUID = 1L; //VersionUID  https://blog.csdn.net/qq_36414165/article/details/69225026
        public static JButton bt3 = new JButton("修改");
        public static JButton bt4 = new JButton("取消");
        public static JLabel lb2 = new JLabel("收入         元"); 
        public static JLabel lb3 = new JLabel("支出         元");
        public static JLabel lb4 = new JLabel("时间");
        public static JLabel lb5 = new JLabel("备注");    
        public static JTextField txt2 = new JTextField();
        public static JTextField txt3 = new JTextField();
        public static JTextField txt4 = new JTextField();
        public static JTextField txt5 = new JTextField();
        String j=JOptionPane.showInputDialog("请输入需要修改的行序号:");
        public  Integer i=Integer.valueOf(j);    
        public  JDialog f2 = new JDialog(Moneymanager.m.f,"修改第"+i+"行数据",true);
        
    public ChangeData(){
        f2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);    //调用任意已注册 WindowListener 的对象后自动隐藏并释放该窗体
        f2.setLayout(null);
        f2.setBounds(220, 200, 600, 300);
        f2.setResizable(false);
        bt3.setBounds(180, 200, 60, 30);f2.add(bt3);bt3.addActionListener(this);
        bt4.setBounds(350, 200, 60, 30);f2.add(bt4);bt4.addActionListener(this);
        lb2.setBounds(100,60,200,40);f2.add(lb2);
        lb2.setFont(new Font("Serif",Font.BOLD,18));
        lb3.setBounds(315,60,200,40);f2.add(lb3);
        lb3.setFont(new Font("Serif",Font.BOLD,18));
        lb4.setBounds(100,90,200,40);f2.add(lb4);
        lb4.setFont(new Font("Serif",Font.BOLD,18));
        lb5.setBounds(100,120,250,40);f2.add(lb5);
        lb5.setFont(new Font("Serif",Font.BOLD,18));
        txt2.setBounds(140,70,55,20);f2.add(txt2);
        txt3.setBounds(355,70,55,20);f2.add(txt3);
        txt4.setBounds(140,100,100,20);f2.add(txt4);
        txt5.setBounds(140, 130, 300, 20);f2.add(txt5);
        
        if(i>new Show().xuhao||i<1){
            JOptionPane.showMessageDialog(null,"没有第"+i+"行记录!");f2.setVisible(false);
        }
        else{
            txt2.setText(new Show().playerInfo[i-1][1]);
            txt3.setText(new Show().playerInfo[i-1][2]);
            txt4.setText(new Show().playerInfo[i-1][3]);
            txt5.setText(new Show().playerInfo[i-1][4]);
            f2.setVisible(true);
        }
    }
    
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==bt3){        
            new Show().getplayerInfo();
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e2) {
                e2.printStackTrace();
            }
            
            try{
                 Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里stu为数据库名               
                 PreparedStatement p = c.prepareStatement("UPDATE Moneymanager set 收入=?, 支出=? ,时间=? ,备注=? where 序号=?");
                 p.setInt(1, Integer.valueOf(txt2.getText()));
                 p.setInt(2, Integer.valueOf(txt3.getText()));
                 p.setString(3, txt4.getText()+" ");
                 p.setString(4, txt5.getText()+" ");
                 p.setInt(5, i);
                 p.executeUpdate();
                 p.close();c.close();
                 JOptionPane.showMessageDialog(null,"修改第"+i+"行数据成功!!    ");
                 f2.setVisible(false); 
                  //System.exit(0);
                 dispose();
            }catch(SQLException e2){
                e2.getStackTrace();
            }      
         }
        else if(e.getSource()==bt4){
            f2.setVisible(false);
            dispose();
        }
    }
    
        /*public static void main(String[] args){
            //new ChangeData();
        }*/
    
    }
     
    //DelData.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.*;
    //删除数据
    class DelData {
        
        Moneymanager m = new Moneymanager();
        String j=JOptionPane.showInputDialog("请输入需要删除的行序号:");
        public  Integer i=Integer.valueOf(j);
        
    public DelData(){
        new Show().getplayerInfo();
        if(i>new Show().xuhao||i<1){
            JOptionPane.showMessageDialog(null,"没有第"+i+"行记录!");
        }
        else{    
        //删除操作
            try{
                Class.forName("com.mysql.jdbc.Driver");//安装驱动
            }catch(java.lang.ClassNotFoundException e){
                System.out.println("forname: " + e.getMessage());
            }
            
            try{
                Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8");//连接数据库
                Statement s = c.createStatement();
                PreparedStatement p1 = c.prepareStatement("delete from Moneymanager where 序号=?");
                PreparedStatement p2 = c.prepareStatement("UPDATE Moneymanager set 序号=? where 序号=?");
                p1.setInt(1, i);
                p1.executeUpdate();
                ResultSet rs=s.executeQuery("select * from Moneymanager");
                int k=1;
                while(rs.next()){
                    if(k>=i&&k<=new Show().xuhao){
                        p2.setInt(1,k);
                        p2.setInt(2,k+1);
                        p2.executeUpdate();
                    }
                    k++;
                }
                Moneymanager.m.f5();
                int l=0;
                for(l=0;l<5;l++) {
                    Moneymanager.m.table.setValueAt("", k-1,l );
                }
                p1.close();p2.close();
                s.close();c.close();
                JOptionPane.showMessageDialog(null,"删除第"+i+"行数据成功!    ");
            }catch(SQLException e){
                System.out.println("SQLException: "+ e.getMessage());    
            }      
        }    
    }
        /*
        public static void main(String[] args) {
            //new DelData();
        }*/
    }
    //FormartData.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import javax.swing.JOptionPane;
    //清空数据
     class FormartData {
        public FormartData(){
            int r=new Show().xuhao;
            try{
                Class.forName("com.mysql.jdbc.Driver");//安装驱动
            }catch(java.lang.ClassNotFoundException e){
                System.out.println("forname: " + e.getMessage());
            }
            
            try{
                Connection c = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8");//连接数据库
                PreparedStatement p = c.prepareStatement("delete from Moneymanager");
                p.executeUpdate();
                p.close();
                c.close();
            }catch(SQLException e){
                System.out.println("SQLException: "+ e.getMessage());    
            } 
            int m=0,n=0;
                            
            for(m=0;m<r;m++)
                for(n=0;n<5;n++){
                    Moneymanager.m.table.setValueAt("", m,n);
                }
            Moneymanager.m.f5();
            JOptionPane.showMessageDialog(null,"数据已成功清空!    ");        
        }
    /*        
        public static void main(String[] args) {
            //new FormartData();
    }
    */
    }

    other

    //Show.java
    package cn.bjxy.zander;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    //show——————————————————————————————————————————————————————————
     public class Show {
         String[][] playerInfo= new String[10000][5];
         int xuhao=0;
         public Show(){
            this.getplayerInfo();    
         }
    
         public void getplayerInfo(){  
             try {
                 Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
             } catch (ClassNotFoundException e1) {
                        e1.printStackTrace();
             }
             try{
                 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                 Statement stmt = conn.createStatement();                       
                 ResultSet rs=stmt.executeQuery("select * from Moneymanager");//将查询得到的结果集给rs
                 int i=0;
                 while(rs.next()){
                     playerInfo[i][0]=String.valueOf(i+1);
                     playerInfo[i][1]=String.valueOf((rs.getInt("收入")));
                     playerInfo[i][2]=String.valueOf((rs.getInt("支出")));
                     playerInfo[i][3]=rs.getString("时间");
                     playerInfo[i][4]=rs.getString("备注");
                     i++;
                 }
                 xuhao=i;conn.close();stmt.close();
             }catch(SQLException e1){
                 e1.getStackTrace();
             } 
        }
         
         
        /* 
        public static void main(String[] args) {
        
        }
    */
    }
    //Count.java
    package cn.bjxy.zander;
    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 javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    
    //报表———————————————————————————————————————————————————————————————————
    class Tongji extends JFrame implements ActionListener{
        
        private static final long serialVersionUID = 1L;
        static JFrame f = new JFrame("财务统计");
        static JLabel lb1 = new JLabel("财务统计:");
        static JLabel lb2 = new JLabel("");
        static JLabel lb3 = new JLabel("");
        static JLabel lb4 = new JLabel("");
        static JLabel lb5 = new JLabel("");
        static JLabel lb6 = new JLabel("");
        //static JLabel lb7 = new JLabel("");
        //static JLabel lb8 = new JLabel("");
        static JButton bt1 = new JButton("确定");
        
    //报表函数
        //总余额
        public String getlb2(){
            int i=0,k=0;
             
            try {
                    Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
               
            try{
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                Statement stmt = conn.createStatement();
                ResultSet rs=stmt.executeQuery("select * from Moneymanager");//将查询得到的结果集给rs
                while(rs.next()){
                   i=i+rs.getInt("收入");
                   k=k+rs.getInt("支出");
                }
            }catch(SQLException e1){
                e1.getStackTrace();
            }   
            //余额
            int sum = i-k;
            String jy;
            if(sum > 50000) {
                jy="已存5万,较为合理";
            }else if(sum <= 50000 && sum >=0 ){
                jy="余额较少,要节约";
            }else {
                jy="请合理规划";
            }
            
            return "总余额:    "+String.valueOf(sum)+"元 ,"+jy;
        }
        
        //当日收入支出
        public String getlb3(){
            int i=0,k=0;
             
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
               
            try{
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                Statement stmt = conn.createStatement();
                ResultSet rs=stmt.executeQuery(" select day, 收入, 支出  from countday where day = (select day(curdate()) ) and month = (select month(curdate()) ) ");//将查询得到的结果集给rs
                while(rs.next()){
                   i=i+rs.getInt("收入");
                   k=k+rs.getInt("支出");
                }
            }catch(SQLException e1){
                e1.getStackTrace();
            }   
            //余额
            return "本日:    收入" + String.valueOf(i) + "元,支出" + String.valueOf(k)+ "元";
        }    
    
        //本月收入支出
        public String getlb4(){
            int i=0,k=0;
             
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
               
            try{
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                Statement stmt = conn.createStatement();
                ResultSet rs=stmt.executeQuery("select month, 收入, 支出  from countmonth where year = (select year(curdate()) ) and month = (select month( curdate() ) )");//将查询得到的结果集给rs
                while(rs.next()){
                   i=i+rs.getInt("收入");
                   k=k+rs.getInt("支出");
                }
            }catch(SQLException e1){
                e1.getStackTrace();
            }   
            //余额
            return "本月:    收入" + String.valueOf(i) + "元,支出" + String.valueOf(k)+ "元";
        }        
        
        //上月收入支出
        public String getlb5(){
            int i=0,k=0;
             
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
               
            try{
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                Statement stmt = conn.createStatement();
                ResultSet rs=stmt.executeQuery("select month, 收入, 支出  from countmonth where year = (select year(curdate()) ) and month = (select month( curdate() )-1 )");//将查询得到的结果集给rs
                while(rs.next()){
                   i=i+rs.getInt("收入");
                   k=k+rs.getInt("支出");
                }
            }catch(SQLException e1){
                e1.getStackTrace();
            }   
            //余额
            return "上月:    收入" + String.valueOf(i) + "元,支出" + String.valueOf(k)+ "元";
        }    
        
        //本年收入支出
        public String getlb6(){
            int i=0,k=0;
             
            try {
                Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
            } catch (ClassNotFoundException e1) {
                e1.printStackTrace();
            }
               
            try{
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/homemoneymanager?user=root&password=369666&useSSL=true&characterEncoding=utf-8"); //建立连接这里student为数据库名
                Statement stmt = conn.createStatement();
                ResultSet rs=stmt.executeQuery("select year, 收入, 支出  from countyear where year = (select max(year) from countyear)");//将查询得到的结果集给rs
                while(rs.next()){
                       i=i+rs.getInt("收入");
                       k=k+rs.getInt("支出");
                    }
            }catch(SQLException e1){
                e1.getStackTrace();
            }   
            //余额
            return "本年:    收入" + String.valueOf(i) + "元,支出" + String.valueOf(k)+ "元";
        }    
        
        
        
        /**************/
        
        //setBounds( x 坐标, y 坐标, width, height)
        
        Tongji(){
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            f.setBounds(300, 300,700,500); //主窗口大小
            f.setLayout(null);f.setResizable(false);
            
            bt1.setBounds(120, 370, 460, 20);
            f.add(bt1);
            bt1.addActionListener(this);
            lb1.setBounds(75, 27, 160, 20);f.add(lb1);
            lb1.setFont(new Font("Serif",Font.BOLD,18));
            
        /**************/
    
            lb2.setText(getlb2());
            lb2.setBounds(120, 70, 460, 20);f.add(lb2);
            lb2.setFont(new Font("Serif",Font.BOLD,24));
            
            lb3.setText(getlb3());
            lb3.setBounds(120, 130, 460, 20);f.add(lb3);
            lb3.setFont(new Font("Serif",Font.BOLD,24));
    
            lb4.setText(getlb4());
            lb4.setBounds(120, 190, 460, 20);f.add(lb4);
            lb4.setFont(new Font("Serif",Font.BOLD,24));
            
            lb5.setText(getlb5());
            lb5.setBounds(120, 250, 460, 20);f.add(lb5);
            lb5.setFont(new Font("Serif",Font.BOLD,24));
            
            lb6.setText(getlb6());
            lb6.setBounds(120, 310, 460, 20);f.add(lb6);
            lb6.setFont(new Font("Serif",Font.BOLD,24));
    /*        
            lb7.setText(getlb3());
            lb7.setBounds(120, 370, 460, 20);f.add(lb6);
            lb7.setFont(new Font("Serif",Font.BOLD,24));    
    */        
        
            f.setVisible(true);
        }
    
        
        public void actionPerformed(ActionEvent   e){
            f.setVisible(false);
        }
        /*
        public static void main(String[] args) {
            //new Tongji();
        }
    */
    }
    //Help.java
    package cn.bjxy.zander;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    //帮助文档——————————————————————————————————————————————————————————————————————————————————
    class Help extends JFrame implements ActionListener{
        
        private static final long serialVersionUID = 1L;
        static JFrame hp = new JFrame("家庭财务管理信息系统帮助");
        static JPanel help = new JPanel();
        static JButton bt = new JButton("退出");
        static JLabel lb1 = new JLabel("帮助:");
        static JLabel lb2 = new JLabel("  1、 修改密码:单击修改密码,按提示框操作;");
        static JLabel lb3 = new JLabel("  2、 修改数据:单击修改数据,然后选择要修改的对象的序号并修改;");
        static JLabel lb4 = new JLabel("  3、 删除数据:单击删除数据,然后选择要删除的对象的序号,点击删除;");
        static JLabel lb5 = new JLabel("  4、 财务统计:单击统计财务统计,显示总余额,日和年流量,本月及上月流量;");
        static JLabel lb6 = new JLabel("  5、 清空数据为清空全部数据,请谨慎操作;");
        static JLabel lb7 = new JLabel("  6、 程序的初始密码为:123,更改密码必须为数字;");
        static JLabel lb8 = new JLabel("  7、 填写收入支出时间备注,点击添加记录即可完成录入");
        static JLabel lb9 = new JLabel("  8、 本程序为Zander学习开发。");
        
    
        public  Help(){
            hp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            help.setLayout(null);hp.setLayout(null);
            hp.setBounds(270, 180, 520, 300);
            help.setBounds(0, 0, 520, 200);
            hp.setResizable(false);
            bt.setBounds(150, 220, 200, 40);    hp.add(bt);    bt.addActionListener(this);
            lb1.setBounds(15, 20, 600, 20);help.add(lb1);    
            lb2.setBounds(15, 40, 600, 20);help.add(lb2);
            lb3.setBounds(15, 60, 600, 20);help.add(lb3);
            lb4.setBounds(15, 80, 600, 20);help.add(lb4);
            lb5.setBounds(15, 100, 600, 20);help.add(lb5);
            lb6.setBounds(15, 120, 600, 20);help.add(lb6);
            lb7.setBounds(15, 140, 600, 20);help.add(lb7);
            lb8.setBounds(15, 160, 600, 20);help.add(lb8);
            lb9.setBounds(15, 180, 600, 20);help.add(lb9);
            hp.add(help);
            hp.setVisible(true);
            help.setVisible(true);
            
        }
            
        public void actionPerformed(ActionEvent   e){
            hp.setVisible(false);
        }
        /*
        public static void main(String[] args) {
            //new Help();
        }
         */
    }

  • 相关阅读:
    有线电视网
    上帝造题的七分钟2 / 花神游历各国
    珂朵莉树(学习笔记)
    [SHOI2015]脑洞治疗仪
    语文1(chin1)- 理理思维
    [SCOI2010]序列操作
    CF915E Physical Education Lessons
    CF896C Willem, Chtholly and Seniorious
    Anaconda 创建环境
    非递归遍历N-ary树Java实现
  • 原文地址:https://www.cnblogs.com/ZanderZhao/p/11358649.html
Copyright © 2011-2022 走看看