结队--复利计算再升级
一、作业
复利计算再升级------------------------------------------------------------
客户在大家的引导下,有了更多的想法:
- 这个数据我经常会填.....帮我预先填上呗?......
- 把界面做得简单漂亮好操作一点呗?
- 能不能帮我转成个APP,我装到手机上就更方便了?
- 我觉得这个很有用,很多人可能都需要这些功能,做到我的微信公众号上吧?
- 能不能不要让我填表单,让我发条消息,或者对着手机说句话就可以了?
每组选一两个方向加以改进,让我们的投资计算与记录工具,达到可以发布给用户使用的版本,并发布博客对此次更新进行说明与总结。
二、任务分配
郑明泽:对我写的窗口代码和以前的代码进行连接修整。
古林萍:首先写出窗口代码和设置界面,然后因为强迫症对界面做了一些细节的调整。
三、估算
估计用时:6h
实际用时:10h
四、窗口代码
1 import java.awt.Color; 2 import java.awt.Font; 3 import java.awt.event.MouseAdapter; 4 import java.awt.event.MouseEvent; 5 import java.text.DecimalFormat; 6 7 import javax.swing.DefaultComboBoxModel; 8 import javax.swing.JButton; 9 import javax.swing.JComboBox; 10 import javax.swing.JFrame; 11 import javax.swing.JLabel; 12 import javax.swing.JTextField; 13 import javax.swing.SwingUtilities; 14 import javax.swing.UIManager; 15 16 import org.dyno.visual.swing.layouts.Constraints; 17 import org.dyno.visual.swing.layouts.GroupLayout; 18 import org.dyno.visual.swing.layouts.Leading; 19 20 21 //VS4E -- DO NOT REMOVE THIS LINE! 22 public class CompundingMain extends JFrame { 23 24 private static final long serialVersionUID = 1L; 25 private JLabel jLabel0; 26 private JLabel jLabel1; 27 private JLabel jLabel2; 28 private JLabel jLabel3; 29 private static JTextField jTextField0; 30 private static JTextField jTextField1; 31 private JTextField jTextField2; 32 private JTextField jTextField3; 33 private JComboBox jComboBox0; 34 //boolean simple_interext=false; 35 //boolean compunding=false; 36 private JLabel jLabel4; 37 private JLabel jLabel5; 38 private JLabel jLabel6; 39 private JLabel jLabel7; 40 private JButton jButton0; 41 public CompundingMain() { 42 initComponents(); 43 } 44 45 private void initComponents() { 46 setLayout(new GroupLayout()); 47 add(getJLabel0(), new Constraints(new Leading(35, 10, 10), new Leading(60, 10, 10))); 48 add(getJLabel1(), new Constraints(new Leading(35, 12, 12), new Leading(100, 21, 10, 10))); 49 add(getJLabel2(), new Constraints(new Leading(35, 12, 12), new Leading(140, 10, 10))); 50 add(getJLabel3(), new Constraints(new Leading(35, 12, 12), new Leading(180, 10, 10))); 51 add(getJTextField0(), new Constraints(new Leading(120, 110, 10, 10), new Leading(60, 12, 12))); 52 add(getJTextField1(), new Constraints(new Leading(120, 110, 12, 12), new Leading(100, 12, 12))); 53 add(getJTextField2(), new Constraints(new Leading(120, 110, 12, 12), new Leading(140, 12, 12))); 54 add(getJTextField3(), new Constraints(new Leading(120, 110, 12, 12), new Leading(180, 12, 12))); 55 add(getJLabel4(), new Constraints(new Leading(35, 12, 12), new Leading(230, 10, 10))); 56 add(getJLabel6(), new Constraints(new Leading(135, 10, 10), new Leading(230, 10, 10))); 57 add(getJLabel7(), new Constraints(new Leading(275, 10, 10), new Leading(259, 10, 10))); 58 add(getJButton0(), new Constraints(new Leading(270, 12, 12), new Leading(120, 12, 12))); 59 add(getJButton1(), new Constraints(new Leading(270, 12, 12), new Leading(170, 12, 12))); 60 add(getJLabel5(), new Constraints(new Leading(35, 12, 12), new Leading(12, 12, 12))); 61 add(getJComboBox0(), new Constraints(new Leading(260, 12, 12), new Leading(12, 12, 12))); 62 setSize(365, 275); 63 } 64 65 private JButton getJButton1() { 66 if (jButton1 == null) { 67 jButton1 = new JButton(); 68 jButton1.setText("计算"); 69 jButton1.addMouseListener(new MouseAdapter() { 70 71 public void mouseClicked(MouseEvent event) { 72 jButton1MouseMouseClicked(event); 73 } 74 }); 75 } 76 return jButton1; 77 } 78 79 private JButton getJButton0() { 80 if (jButton0 == null) { 81 jButton0 = new JButton(); 82 jButton0.setText("清除"); 83 } 84 return jButton0; 85 } 86 87 private JLabel getJLabel7() { 88 if (jLabel7 == null) { 89 jLabel7 = new JLabel(); 90 jLabel7.setText("@237-glp_moliny"); 91 jLabel7.setFont(new Font("", 1, 10)); 92 jLabel7.setForeground(Color.lightGray); 93 } 94 return jLabel7; 95 } 96 97 private JLabel getJLabel6() { 98 if (jLabel6 == null) { 99 jLabel6 = new JLabel(); 100 jLabel6.setText("请输入数据"); 101 jLabel6.setFont(new Font("楷体", 1, 20)); 102 jLabel6.setForeground(Color.red); 103 } 104 return jLabel6; 105 } 106 107 private JLabel getJLabel5() { 108 if (jLabel5 == null) { 109 jLabel5 = new JLabel(); 110 jLabel5.setFont(new Font("楷体", Font.BOLD, 20)); 111 jLabel5.setText("复利计算器1.0"); 112 } 113 return jLabel5; 114 } 115 116 private JLabel getJLabel4() { 117 if (jLabel4 == null) { 118 jLabel4 = new JLabel(); 119 jLabel4.setText("计算结果:"); 120 jLabel4.setFont(new Font("楷体",1,20)); 121 } 122 return jLabel4; 123 } 124 125 private JComboBox getJComboBox0() { 126 if (jComboBox0 == null) { 127 jComboBox0 = new JComboBox(); 128 jComboBox0.setModel(new DefaultComboBoxModel(new Object[] { "求最终金额", "求存款年份", "求存款利息", "求存款本金", "求等额投资", "求贷款还钱","看投资记录" })); 129 jComboBox0.setDoubleBuffered(false); 130 jComboBox0.setBorder(null); 131 jComboBox0.addMouseListener(new MouseAdapter() { 132 133 public void mouseClicked(MouseEvent event) { 134 jComboBox0MouseMouseClicked(event); 135 } 136 }); 137 } 138 return jComboBox0; 139 } 140 141 private JTextField getJTextField3() { 142 if (jTextField3 == null) { 143 jTextField3 = new JTextField(); 144 } 145 return jTextField3; 146 } 147 148 private JTextField getJTextField2() { 149 if (jTextField2 == null) { 150 jTextField2 = new JTextField(); 151 } 152 return jTextField2; 153 } 154 155 private JTextField getJTextField1() { 156 if (jTextField1 == null) { 157 jTextField1 = new JTextField(); 158 } 159 return jTextField1; 160 } 161 162 private JTextField getJTextField0() { 163 if (jTextField0 == null) { 164 jTextField0 = new JTextField(); 165 } 166 return jTextField0; 167 } 168 169 private JLabel getJLabel3() { 170 if (jLabel3 == null) { 171 jLabel3 = new JLabel(); 172 jLabel3.setText("复利次数:"); 173 } 174 return jLabel3; 175 } 176 177 private JLabel getJLabel2() { 178 if (jLabel2 == null) { 179 jLabel2 = new JLabel(); 180 jLabel2.setText("存款年份:"); 181 } 182 return jLabel2; 183 } 184 185 private JLabel getJLabel1() { 186 if (jLabel1 == null) { 187 jLabel1 = new JLabel(); 188 jLabel1.setText("存款利息:"); 189 } 190 return jLabel1; 191 } 192 193 private JLabel getJLabel0() { 194 if (jLabel0 == null) { 195 jLabel0 = new JLabel(); 196 jLabel0.setText("存款本金:"); 197 } 198 return jLabel0; 199 } 200 201 private static void installLnF() { 202 try { 203 String lnfClassname = PREFERRED_LOOK_AND_FEEL; 204 if (lnfClassname == null) 205 lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName(); 206 UIManager.setLookAndFeel(lnfClassname); 207 } catch (Exception e) { 208 System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL 209 + " on this platform:" + e.getMessage()); 210 } 211 } 212 213 /** 214 * Main entry of the class. 215 * Note: This class is only created so that you can easily preview the result at runtime. 216 * It is not expected to be managed by the designer. 217 * You can modify it as you like. 218 */ 219 public static void main(String[] args) { 220 installLnF(); 221 SwingUtilities.invokeLater(new Runnable() { 222 public void run() { 223 CompundingMain frame = new CompundingMain(); 224 frame.setDefaultCloseOperation(CompundingMain.EXIT_ON_CLOSE); 225 frame.setTitle("Moliny"); 226 frame.getContentPane().setPreferredSize(frame.getSize()); 227 frame.pack(); 228 frame.setLocationRelativeTo(null); 229 frame.setVisible(true); 230 } 231 }); 232 } 233 234 Calculate cal; 235 private JButton jButton1; 236 private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel"; 237 private void jButton1MouseMouseClicked(MouseEvent event) { 238 239 DecimalFormat df = new DecimalFormat( "0.0000"); 240 double P = Double.valueOf(jTextField0.getText()); 241 double i = Double.valueOf(jTextField1.getText()); 242 int n = Integer.valueOf(jTextField2.getText()); 243 int k = Integer.valueOf(jTextField3.getText()); 244 double F=1.0000; 245 F=P*(Math.pow(i/k+1,k*n)); 246 //F = cal.compunding(P, i, n, k); 247 jLabel6.setText(String.valueOf(df.format(F))); 248 } 249 250 private void jComboBox0MouseMouseClicked(MouseEvent event) { 251 Object str; 252 str=jComboBox0.getSelectedItem(); 253 if (str == "求最终金额") { 254 jLabel1.setText("存款利息"); 255 jLabel2.setText("存款年份"); 256 }else if (str == "求存款年份") { 257 jLabel1.setText("最终金额"); 258 jLabel2.setText("存款利息"); 259 } 260 } 261 }
五、结果
六、总结
从开始的c语言,到java,再到java文件存储,再到界面设置,这他妈的就是一个无底洞呀,根本想不到后面还会有什么。。。。。
posted on 2016-04-14 22:00 Glp_Moliny 阅读(338) 评论(3) 编辑 收藏 举报