对比.java
上传用户:qzpk678
上传日期:2021-04-29
资源大小:10k
文件大小:5k
- package src;
- import java.awt.*;
- import java.awt.event.*;
- import java.sql.*;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- public class 对比 extends JFrame
- {
- private static final long serialVersionUID = 1L;
- Double m,n,m1,m2,m3,m4,m5,m6,m7,m8,m9,n1,n2,n3,n4,n5,m55,m66,m77,m88,m99;
- JPanel p1=new JPanel();
- Font font=new Font("Monospaced" ,Font.BOLD,20);
- JButton n11=new JButton("退出");
- JLabel jl1=new JLabel("吃饭喝水");
- JLabel jl2=new JLabel("买书买报");
- JLabel jl3=new JLabel("请同学吃饭");
- JLabel jl4=new JLabel("出门坐车");
- JLabel jl5=new JLabel("其他支出");
- Connection con;
- Statement sql;
- ResultSet rs;
- public 对比(String s)
- {
- try
- {
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- }
- catch(ClassNotFoundException e1)
- {
- System.out.println(""+e1);
- }
-
- try
- {
- String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
- String user="chenzhi";
- String password="chenzhi";
- con = DriverManager.getConnection(uri,user,password);
- sql= con.createStatement();
- rs=sql.executeQuery("SELECT*FROM inMoney");
- while(rs.next())
- {
- m1=Double.parseDouble(rs.getString(1));
- m2=Double.parseDouble(rs.getString(2));
- m3=Double.parseDouble(rs.getString(3));
- m4=Double.parseDouble(rs.getString(4));
- m=m1+m2+m3+m4;
- }
- con.close();
- }
- catch(SQLException e)
- {
- System.out.println(e);
- }
- try
- {
- String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
- String user="chenzhi";
- String password="chenzhi";
- con = DriverManager.getConnection(uri,user,password);
- sql= con.createStatement();
- rs=sql.executeQuery("SELECT*FROM outMoney");
- m5=m6=m7=m8=m9=0.0;
- while(rs.next())
- {
- m55=Double.parseDouble(rs.getString(1));
- m66=Double.parseDouble(rs.getString(2));
- m77=Double.parseDouble(rs.getString(3));
- m88=Double.parseDouble(rs.getString(4));
- m99=Double.parseDouble(rs.getString(5));
- m5=m5+m55;
- m6=m6+m66;
- m7=m7+m77;
- m8=m8+m88;
- m9=m9+m99;
- }
- n=m5+m6+m7+m8+m9;
- con.close();
- }
- catch(SQLException e)
- {
- System.out.println(e);
- }
- try
- {
- String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
- String user="chenzhi";
- String password="chenzhi";
- con = DriverManager.getConnection(uri,user,password);
- sql= con.createStatement();
- rs=sql.executeQuery("SELECT*FROM setMoney");
- while(rs.next())
- {
- n1=0.01*Double.parseDouble(rs.getString(1));
- n2=0.01*Double.parseDouble(rs.getString(2));
- n3=0.01*Double.parseDouble(rs.getString(3));
- n4=0.01*Double.parseDouble(rs.getString(4));
- n5=0.01*Double.parseDouble(rs.getString(5));
- }
- con.close();
- }
- catch(SQLException e)
- {
- System.out.println(e);
- }
- n1=n1*m;
- n2=n2*m;
- n3=n3*m;
- n4=n4*m;
- n5=n5*m;
- JLabel j11=new JLabel(duibi(n1,m5));
- JLabel j21=new JLabel(duibi(n2,m6));
- JLabel j31=new JLabel(duibi(n3,m7));
- JLabel j41=new JLabel(duibi(n4,m8));
- JLabel j51=new JLabel(duibi(n5,m9));
- JLabel l1=new JLabel("本月收入共"+m+"元,共支出"+n+"元");
- setTitle(s);
- setResizable(false);
- setBounds(200, 100, 800, 700);
- setVisible(true);
- setLayout(null);
- p1.add(l1);
- l1.setForeground(Color.magenta);
- l1.setFont(font);
- l1.setBounds(300, 0, 500, 50);
- p1.setBounds(0, 0, 800, 50);
- add(p1);
- jl1.setBounds(100, 100, 150, 50);
- j11.setBounds(250, 100, 400, 50);
- jl2.setBounds(100, 180, 150, 50);
- j21.setBounds(250, 180, 400, 50);
- jl3.setBounds(100, 260, 150, 50);
- j31.setBounds(250, 260, 400, 50);
- jl4.setBounds(100, 340, 150, 50);
- j41.setBounds(250, 340, 400, 50);
- jl5.setBounds(100, 420, 150, 50);
- j51.setBounds(250, 420, 400, 50);
- n11.setBounds(500, 550, 100, 50);
- add(n11);
- add(jl1);
- add(jl2);
- add(jl3);
- add(jl4);
- add(jl5);
- add(j11);
- add(j21);
- add(j31);
- add(j41);
- add(j51);
- n11.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- dispose();
- System.exit(0);
- }
- });
- validate();
- }
-
- String duibi(Double n,Double m)
- {
- String s=new String();
- if(m<1.1*n&&m>0.9*n)
- {
- s=" 实际使用和设置使用相差无几";
- }
- else if(m>1.1*n&&m<1.5*n)
- {
- s=" 实际使用比设置使用稍多";
- }
- else if(m>1.5*n)
- {
- s=" 超支啦!!";
- }
- else if(m<0.9*n)
- {
- s=" 节省的好孩子啊!!";
- }
- s="设置使用"+n+"元,实际使用"+m+"元"+s;
- return s;
- }
- }
-