对比.java
上传用户:qzpk678
上传日期:2021-04-29
资源大小:10k
文件大小:5k
源码类别:

家庭/个人应用

开发平台:

Java

  1. package src;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.sql.*;
  5. import javax.swing.JButton;
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8. import javax.swing.JPanel;
  9. public class 对比 extends JFrame
  10. {
  11. private static final long serialVersionUID = 1L;
  12. Double m,n,m1,m2,m3,m4,m5,m6,m7,m8,m9,n1,n2,n3,n4,n5,m55,m66,m77,m88,m99;
  13. JPanel p1=new JPanel();
  14.     Font font=new Font("Monospaced" ,Font.BOLD,20);
  15.     JButton n11=new JButton("退出");
  16. JLabel jl1=new JLabel("吃饭喝水");
  17. JLabel jl2=new JLabel("买书买报");
  18. JLabel jl3=new JLabel("请同学吃饭");
  19. JLabel jl4=new JLabel("出门坐车");
  20. JLabel jl5=new JLabel("其他支出");
  21. Connection con;
  22. Statement sql;
  23. ResultSet rs;
  24. public 对比(String s)
  25. {
  26. try
  27.    {
  28. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  29.    }
  30.    catch(ClassNotFoundException e1)
  31.    {
  32. System.out.println(""+e1);
  33.    }
  34.    try
  35.    {
  36. String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
  37. String user="chenzhi";
  38. String password="chenzhi";
  39.     con = DriverManager.getConnection(uri,user,password);
  40. sql= con.createStatement();
  41. rs=sql.executeQuery("SELECT*FROM inMoney");
  42. while(rs.next())
  43. {
  44. m1=Double.parseDouble(rs.getString(1));
  45. m2=Double.parseDouble(rs.getString(2));
  46. m3=Double.parseDouble(rs.getString(3));
  47. m4=Double.parseDouble(rs.getString(4));  
  48. m=m1+m2+m3+m4;
  49. }
  50. con.close();
  51.   }
  52.   catch(SQLException e)
  53.   {
  54.    System.out.println(e);
  55.   }
  56.   try
  57.    {
  58. String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
  59. String user="chenzhi";
  60. String password="chenzhi";
  61.     con = DriverManager.getConnection(uri,user,password);
  62. sql= con.createStatement();
  63. rs=sql.executeQuery("SELECT*FROM outMoney");
  64. m5=m6=m7=m8=m9=0.0;
  65. while(rs.next())
  66. {
  67. m55=Double.parseDouble(rs.getString(1));
  68. m66=Double.parseDouble(rs.getString(2));
  69. m77=Double.parseDouble(rs.getString(3));
  70. m88=Double.parseDouble(rs.getString(4));   
  71. m99=Double.parseDouble(rs.getString(5));
  72. m5=m5+m55;
  73. m6=m6+m66;
  74. m7=m7+m77;
  75. m8=m8+m88;
  76. m9=m9+m99;
  77. }
  78. n=m5+m6+m7+m8+m9;
  79. con.close();
  80.   }
  81.   catch(SQLException e)
  82.   {
  83.    System.out.println(e);
  84.   }
  85.   try
  86.    {
  87. String uri="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatebaseName=design";
  88. String user="chenzhi";
  89. String password="chenzhi";
  90.     con = DriverManager.getConnection(uri,user,password);
  91. sql= con.createStatement();
  92. rs=sql.executeQuery("SELECT*FROM setMoney");
  93. while(rs.next())
  94. {
  95. n1=0.01*Double.parseDouble(rs.getString(1));
  96. n2=0.01*Double.parseDouble(rs.getString(2));
  97. n3=0.01*Double.parseDouble(rs.getString(3));
  98. n4=0.01*Double.parseDouble(rs.getString(4));   
  99. n5=0.01*Double.parseDouble(rs.getString(5));
  100. }
  101. con.close();
  102.   }
  103.   catch(SQLException e)
  104.   {
  105.    System.out.println(e);
  106.   }
  107.   n1=n1*m;
  108.   n2=n2*m;
  109.   n3=n3*m;
  110.   n4=n4*m;
  111.   n5=n5*m;
  112.   JLabel j11=new JLabel(duibi(n1,m5));
  113.   JLabel j21=new JLabel(duibi(n2,m6));
  114.   JLabel j31=new JLabel(duibi(n3,m7));
  115.   JLabel j41=new JLabel(duibi(n4,m8));
  116.   JLabel j51=new JLabel(duibi(n5,m9));
  117.   JLabel l1=new JLabel("本月收入共"+m+"元,共支出"+n+"元");
  118.   setTitle(s);
  119.   setResizable(false);
  120.   setBounds(200, 100, 800, 700);
  121.   setVisible(true);
  122.   setLayout(null);
  123.   p1.add(l1);
  124.   l1.setForeground(Color.magenta);
  125.   l1.setFont(font);
  126.   l1.setBounds(300, 0, 500, 50);
  127.   p1.setBounds(0, 0, 800, 50);
  128.   add(p1);
  129.   jl1.setBounds(100, 100, 150, 50);
  130.   j11.setBounds(250, 100, 400, 50);
  131.   jl2.setBounds(100, 180, 150, 50);
  132.   j21.setBounds(250, 180, 400, 50);
  133.   jl3.setBounds(100, 260, 150, 50);
  134.   j31.setBounds(250, 260, 400, 50);
  135.   jl4.setBounds(100, 340, 150, 50);
  136.   j41.setBounds(250, 340, 400, 50);
  137.   jl5.setBounds(100, 420, 150, 50);
  138.   j51.setBounds(250, 420, 400, 50);
  139.   n11.setBounds(500, 550, 100, 50);
  140.   add(n11);
  141.   add(jl1);
  142.   add(jl2);
  143.   add(jl3);
  144.   add(jl4);
  145.   add(jl5);
  146.   add(j11);
  147.   add(j21);
  148.   add(j31);
  149.   add(j41);
  150.   add(j51);
  151.   n11.addActionListener(new ActionListener(){
  152. public void actionPerformed(ActionEvent e) {
  153. dispose();
  154. System.exit(0);
  155. }
  156. });
  157.   validate();
  158. }   
  159. String duibi(Double n,Double m)
  160. {
  161. String s=new String();
  162. if(m<1.1*n&&m>0.9*n)
  163. {
  164. s="  实际使用和设置使用相差无几";
  165. }
  166. else if(m>1.1*n&&m<1.5*n)
  167. {
  168. s="  实际使用比设置使用稍多";
  169. }
  170. else if(m>1.5*n)
  171. {
  172.     s="  超支啦!!";
  173. }
  174.     else if(m<0.9*n)
  175. {
  176.     s="  节省的好孩子啊!!";
  177. }
  178. s="设置使用"+n+"元,实际使用"+m+"元"+s;
  179. return s;
  180. }
  181. }
  182.