标签:
(1)设置数据常用值;
(2)设置美化背景;
(3)完成SQL读写,每次打开复利计算器可以看到最近结果;
1 package Fuli; 2 import java.awt.Image; 3 import java.awt.event.MouseAdapter; 4 import java.awt.event.MouseEvent; 5 6 import javax.swing.Icon; 7 import javax.swing.ImageIcon; 8 import javax.swing.JButton; 9 import javax.swing.JFrame; 10 import javax.swing.JLabel; 11 import javax.swing.JOptionPane; 12 import javax.swing.JTextField; 13 14 import org.dyno.visual.swing.layouts.Bilateral; 15 import org.dyno.visual.swing.layouts.Constraints; 16 import org.dyno.visual.swing.layouts.GroupLayout; 17 import org.dyno.visual.swing.layouts.Leading; 18 19 20 //VS4E -- DO NOT REMOVE THIS LINE! 21 public class PI extends JFrame { 22 23 private static final long serialVersionUID = 1L; 24 private JTextField jTextField0; 25 private JTextField jTextField2; 26 private JTextField jTextField3; 27 private JTextField jTextField1; 28 private JLabel jLabel0; 29 private JLabel jLabel2; 30 private JLabel jLabel3; 31 private JLabel jLabel1; 32 private JTextField jTextField4; 33 private JTextField jTextField5; 34 private JTextField jTextField6; 35 private JLabel jLabel4; 36 private JLabel jLabel5; 37 private JLabel jLabel6; 38 private JButton jButton0; 39 private JButton jButton1; 40 private JButton jButton2; 41 private JButton jButton3; 42 43 public PI() { 44 initComponents(); 45 } 46 47 private void initComponents() { 48 setTitle("组合计算"); 49 setLayout(new GroupLayout()); 50 add(getJTextField0(), new Constraints(new Leading(108, 10, 10), new Leading(66, 10, 10))); 51 add(getJTextField2(), new Constraints(new Leading(108, 38, 12, 12), new Leading(161, 10, 10))); 52 add(getJTextField3(), new Constraints(new Leading(108, 38, 12, 12), new Leading(210, 10, 10))); 53 add(getJTextField1(), new Constraints(new Leading(108, 38, 12, 12), new Leading(112, 10, 10))); 54 add(getJLabel0(), new Constraints(new Leading(51, 10, 10), new Leading(68, 12, 12))); 55 add(getJLabel2(), new Constraints(new Leading(51, 8, 12, 12), new Leading(163, 12, 12))); 56 add(getJLabel3(), new Constraints(new Leading(51, 12, 12), new Leading(212, 12, 12))); 57 add(getJLabel1(), new Constraints(new Leading(54, 8, 10, 10), new Leading(114, 12, 12))); 58 add(getJTextField4(), new Constraints(new Leading(291, 38, 10, 10), new Leading(66, 12, 12))); 59 add(getJTextField5(), new Constraints(new Leading(291, 38, 12, 12), new Leading(114, 12, 12))); 60 add(getJTextField6(), new Constraints(new Leading(291, 38, 12, 12), new Leading(161, 12, 12))); 61 add(getJLabel4(), new Constraints(new Leading(245, 8, 10, 10), new Leading(68, 12, 12))); 62 add(getJLabel5(), new Constraints(new Leading(245, 8, 12, 12), new Leading(116, 12, 12))); 63 add(getJLabel6(), new Constraints(new Leading(247, 14, 10, 10), new Leading(163, 12, 12))); 64 add(getJButton0(), new Constraints(new Leading(472, 10, 10), new Leading(60, 12, 12))); 65 add(getJButton1(), new Constraints(new Leading(472, 12, 12), new Leading(116, 12, 12))); 66 add(getJButton2(), new Constraints(new Leading(472, 12, 12), new Leading(174, 10, 10))); 67 add(getJButton3(), new Constraints(new Leading(270, 12, 12), new Leading(270, 10, 10))); 68 add(getJLabel7(), new Constraints(new Bilateral(0, 0, 41), new Leading(5, 348, 10, 10))); 69 setSize(610, 357); 70 } 71 ImageIcon img=new ImageIcon("src//Fuli//b.jpg"); 72 private JLabel getJLabel7() { 73 if (jLabel7 == null) { 74 jLabel7 = new JLabel(); 75 jLabel7.setText("jLabel7"); 76 img.setImage(img.getImage().getScaledInstance(img.getIconWidth(), img.getIconHeight(), Image.SCALE_DEFAULT)); 77 jLabel7.setIcon(img); 78 } 79 return jLabel7; 80 } 81 82 private JButton getJButton3() { 83 if (jButton3 == null) { 84 jButton3 = new JButton(); 85 jButton3.setText("计算结果"); 86 jButton3.addMouseListener(new MouseAdapter() { 87 88 public void mouseClicked(MouseEvent event) { 89 jButton3MouseMouseClicked(event); 90 } 91 }); 92 } 93 return jButton3; 94 } 95 96 private JButton getJButton2() { 97 if (jButton2 == null) { 98 jButton2 = new JButton(); 99 jButton2.setText("加入定投"); 100 jButton2.addMouseListener(new MouseAdapter() { 101 102 public void mouseClicked(MouseEvent event) { 103 jButton2MouseMouseClicked(event); 104 } 105 }); 106 } 107 return jButton2; 108 } 109 110 private JButton getJButton1() { 111 if (jButton1 == null) { 112 jButton1 = new JButton(); 113 jButton1.setText("加入复利"); 114 jButton1.addMouseListener(new MouseAdapter() { 115 116 public void mouseClicked(MouseEvent event) { 117 jButton1MouseMouseClicked(event); 118 } 119 }); 120 } 121 return jButton1; 122 } 123 124 private JButton getJButton0() { 125 if (jButton0 == null) { 126 jButton0 = new JButton(); 127 jButton0.setText("加入单利"); 128 jButton0.addMouseListener(new MouseAdapter() { 129 130 public void mouseClicked(MouseEvent event) { 131 jButton0MouseMouseClicked(event); 132 } 133 }); 134 } 135 return jButton0; 136 } 137 138 private JLabel getJLabel6() { 139 if (jLabel6 == null) { 140 jLabel6 = new JLabel(); 141 jLabel6.setText("n"); 142 } 143 return jLabel6; 144 } 145 146 private JLabel getJLabel5() { 147 if (jLabel5 == null) { 148 jLabel5 = new JLabel(); 149 jLabel5.setText("x"); 150 } 151 return jLabel5; 152 } 153 154 private JLabel getJLabel4() { 155 if (jLabel4 == null) { 156 jLabel4 = new JLabel(); 157 jLabel4.setText("a"); 158 } 159 return jLabel4; 160 } 161 162 private JTextField getJTextField6() { 163 if (jTextField6 == null) { 164 jTextField6 = new JTextField(); 165 jTextField6.setText("0 "); 166 } 167 return jTextField6; 168 } 169 170 private JTextField getJTextField5() { 171 if (jTextField5 == null) { 172 jTextField5 = new JTextField(); 173 jTextField5.setText("0.15"); 174 } 175 return jTextField5; 176 } 177 178 private JTextField getJTextField4() { 179 if (jTextField4 == null) { 180 jTextField4 = new JTextField(); 181 jTextField4.setText("0 "); 182 } 183 return jTextField4; 184 } 185 186 private JLabel getJLabel1() { 187 if (jLabel1 == null) { 188 jLabel1 = new JLabel(); 189 jLabel1.setText("i"); 190 } 191 return jLabel1; 192 } 193 194 private JLabel getJLabel3() { 195 if (jLabel3 == null) { 196 jLabel3 = new JLabel(); 197 jLabel3.setText("A"); 198 } 199 return jLabel3; 200 } 201 202 private JLabel getJLabel2() { 203 if (jLabel2 == null) { 204 jLabel2 = new JLabel(); 205 jLabel2.setText("n"); 206 } 207 return jLabel2; 208 } 209 210 private JLabel getJLabel0() { 211 if (jLabel0 == null) { 212 jLabel0 = new JLabel(); 213 jLabel0.setText("P"); 214 } 215 return jLabel0; 216 } 217 218 private JTextField getJTextField1() { 219 if (jTextField1 == null) { 220 jTextField1 = new JTextField(); 221 jTextField1.setText("0.2 "); 222 } 223 return jTextField1; 224 } 225 226 private JTextField getJTextField3() { 227 if (jTextField3 == null) { 228 jTextField3 = new JTextField(); 229 jTextField3.setText("0 "); 230 } 231 return jTextField3; 232 } 233 234 private JTextField getJTextField2() { 235 if (jTextField2 == null) { 236 jTextField2 = new JTextField(); 237 jTextField2.setText("0 "); 238 } 239 return jTextField2; 240 } 241 242 private JTextField getJTextField0() { 243 if (jTextField0 == null) { 244 jTextField0 = new JTextField(); 245 jTextField0.setText("0 "); 246 } 247 return jTextField0; 248 } 249 250 double sum=0; 251 Icon ico=new ImageIcon("./src/Fuli.png"); 252 private JLabel jLabel7; 253 254 private void jButton0MouseMouseClicked(MouseEvent event) { 255 try 256 {double P=Double.parseDouble(getJTextField0().getText()), 257 i=Double.parseDouble(getJTextField1().getText()), 258 n=Double.parseDouble(getJTextField2().getText()), 259 A=Double.parseDouble(getJTextField3().getText()); 260 double F=0; 261 if(n>60) 262 JOptionPane.showMessageDialog(jButton0, "超过60年限","出错", JOptionPane.INFORMATION_MESSAGE); 263 else if(i>1) 264 JOptionPane.showMessageDialog(jButton0, "利率应小于1","出错", JOptionPane.INFORMATION_MESSAGE); 265 266 267 if(i==0&&P==0&&n==0&&A==0) 268 JOptionPane.showMessageDialog(jButton0, "你没有输入任何数", "真的福利",JOptionPane.INFORMATION_MESSAGE,ico);else{ 269 F=sumofthey.F1(P, i, n, A); 270 sum=sum+F; 271 JOptionPane.showMessageDialog(jButton0, "F="+F,"本次计算结果", JOptionPane.INFORMATION_MESSAGE);}}catch(Exception e){JOptionPane.showMessageDialog(jButton0, "请输入数字","出错", JOptionPane.INFORMATION_MESSAGE);} 272 } 273 274 private void jButton1MouseMouseClicked(MouseEvent event) { 275 try 276 {double P=Double.parseDouble(getJTextField0().getText()), 277 i=Double.parseDouble(getJTextField1().getText()), 278 n=Double.parseDouble(getJTextField2().getText()), 279 A=Double.parseDouble(getJTextField3().getText()), 280 F=0; 281 if(n>60) 282 JOptionPane.showMessageDialog(jButton0, "超过60年限","出错", JOptionPane.INFORMATION_MESSAGE); 283 else if(i>1) 284 JOptionPane.showMessageDialog(jButton0, "利率应小于1","出错", JOptionPane.INFORMATION_MESSAGE); 285 286 287 if(i==0&&P==0&&n==0&&A==0&&F==0) 288 JOptionPane.showMessageDialog(jButton0, "你没有输入任何数", "真的福利",JOptionPane.INFORMATION_MESSAGE,ico);else{ 289 F=sumofthey.F2(P, i, n, A); 290 sum=sum+F; 291 JOptionPane.showMessageDialog(jButton0, "F="+F,"本次计算结果", JOptionPane.INFORMATION_MESSAGE);}}catch(Exception e){JOptionPane.showMessageDialog(jButton0, "请输入数字","出错", JOptionPane.INFORMATION_MESSAGE);} 292 293 } 294 295 private void jButton2MouseMouseClicked(MouseEvent event) { 296 try{ 297 double a=Double.parseDouble(getJTextField4().getText()), 298 x=Double.parseDouble(getJTextField5().getText()), 299 n=Double.parseDouble(getJTextField6().getText()); 300 if(n>60) 301 JOptionPane.showMessageDialog(jButton0, "超过60年限","出错", JOptionPane.INFORMATION_MESSAGE); 302 else if(x>1) 303 JOptionPane.showMessageDialog(jButton0, "利率应小于1","出错", JOptionPane.INFORMATION_MESSAGE); 304 305 double M=sumofthey.M(a, x, n);sum=sum+M; 306 if(x==0&&n==0&&a==0) 307 JOptionPane.showMessageDialog(jButton0, "你没有输入任何数", "真的福利",JOptionPane.INFORMATION_MESSAGE,ico); 308 else 309 JOptionPane.showMessageDialog(jButton0, "M="+M,"计算结果", JOptionPane.INFORMATION_MESSAGE);} 310 catch(Exception e){JOptionPane.showMessageDialog(jButton0, "请输入数字","出错", JOptionPane.INFORMATION_MESSAGE);} 311 } 312 313 private void jButton3MouseMouseClicked(MouseEvent event) { 314 JOptionPane.showMessageDialog(jButton0, "SUM="+sum,"计算结果", JOptionPane.INFORMATION_MESSAGE); 315 } 316 }
1 package Fuli; 2 3 import java.util.List; 4 5 import org.hibernate.Session; 6 import org.hibernate.SessionFactory; 7 import org.hibernate.SharedSessionContract; 8 import org.hibernate.cfg.Configuration; 9 10 11 public class SQL_mainFrame { 12 public static void write(int CS,double P,double i,double n,double A,double F){ 13 14 W_SQL_mainFrame WS=new W_SQL_mainFrame(); 15 WS.setA(A); 16 try{ 17 WS.setCS(CS); 18 WS.setF(F); 19 WS.seti(i); 20 WS.setn(n); 21 WS.setP(P);} 22 catch(Exception e){ 23 CS++; 24 WS.setCS(CS); 25 WS.setF(F); 26 WS.seti(i); 27 WS.setn(n); 28 WS.setP(P); 29 } 30 Configuration cfg = new Configuration(); 31 SessionFactory sf = cfg.configure().buildSessionFactory(); 32 Session session = sf.openSession(); 33 session.beginTransaction(); 34 session.save(WS); 35 session.getTransaction().commit(); 36 session.close(); 37 sf.close(); 38 39 40 } 41 public static String readF() 42 { 43 Configuration cfg = new Configuration(); 44 SessionFactory sf = cfg.configure().buildSessionFactory(); 45 Session session = sf.openSession(); 46 String a=session.createSQLQuery("SELECT F FROM Fuli_User_mainFrame").list().toString(); 47 48 49 return a; 50 } 51 public static String readi() 52 { 53 Configuration cfg = new Configuration(); 54 SessionFactory sf = cfg.configure().buildSessionFactory(); 55 Session session = sf.openSession(); 56 String a=session.createSQLQuery("SELECT i FROM Fuli_User_mainFrame").list().toString(); 57 58 return a; 59 } 60 61 public static String readn() 62 { 63 Configuration cfg = new Configuration(); 64 SessionFactory sf = cfg.configure().buildSessionFactory(); 65 Session session = sf.openSession(); 66 String a=session.createSQLQuery("SELECT n FROM Fuli_User_mainFrame").list().toString(); 67 68 69 return a; 70 } 71 public static String readA() 72 { 73 Configuration cfg = new Configuration(); 74 SessionFactory sf = cfg.configure().buildSessionFactory(); 75 Session session = sf.openSession(); 76 String a=session.createSQLQuery("SELECT A FROM Fuli_User_mainFrame").list().toString(); 77 78 79 return a; 80 } 81 public static String readP() 82 { 83 Configuration cfg = new Configuration(); 84 SessionFactory sf = cfg.configure().buildSessionFactory(); 85 Session session = sf.openSession(); 86 String a=session.createSQLQuery("SELECT P FROM Fuli_User_mainFrame").list().toString(); 87 88 89 return a; 90 } 91 }
详细代码地址:https://github.com/rongjielong/New-6.0/tree/master/New-6.0-Fuli
容杰龙:背景图片插入、预设默认值
卓炜杰:SQL读写
这次结对我们遇到较多的问题,也一起克服了一些问题,虽然在讨论功能模块的时候有分歧,可是我们还是商议到大家双方都比较满意的状况。虽然有一些功能还没完善,例如做成app等,这些功能我们还在努力建设中。我们都比较努力地查找资料,寻找各种方案解决,因此比较耗时。我觉得越是往深处去做,越觉得复杂程度越大,发现问题也更多。
标签:
原文地址:http://www.cnblogs.com/57rongjielong/p/5392274.html