package com.zhadan.Frame;
import java.awt.event.MouseAdapter;
//VS4E -- DO NOT REMOVE THIS LINE!
public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel jLabel0;
private JTextField jTextField0;
private JLabel jLabel1;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField3;
private JLabel jLabel3;
private JLabel jLabel2;
private JButton jButton0;
public MainFrame() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJLabel0(), new Constraints(new Leading(22, 32, 10, 10), new Leading(36, 24, 12, 12)));
add(getJTextField0(), new Constraints(new Leading(66, 219, 10, 10), new Leading(37, 23, 12, 12)));
add(getJLabel1(), new Constraints(new Leading(22, 28, 12, 12), new Leading(78, 23, 12, 12)));
add(getJTextField1(), new Constraints(new Leading(66, 218, 12, 12), new Leading(78, 12, 12)));
add(getJTextField2(), new Constraints(new Leading(66, 218, 12, 12), new Leading(121, 12, 12)));
add(getJLabel3(), new Constraints(new Leading(22, 12, 12), new Leading(161, 22, 12, 12)));
add(getJLabel2(), new Constraints(new Leading(22, 12, 12), new Leading(121, 22, 12, 12)));
add(getJComboBox0(), new Constraints(new Leading(109, 10, 10), new Leading(202, 12, 12)));
add(getJLabel4(), new Constraints(new Leading(89, 10, 10), new Leading(179, -8, 10, 10)));
add(getJButton0(), new Constraints(new Leading(17, 10, 10), new Leading(202, 12, 12)));
add(getJTextField3(), new Constraints(new Leading(66, 218, 12, 12), new Leading(157, 23, 10, 10)));
add(getJLabel5(), new Constraints(new Leading(56, 10, 10), new Leading(265, 10, 10)));
add(getJLabel6(), new Constraints(new Leading(137, 12, 12), new Leading(12, 12, 12)));
setSize(321, 314);
}
private JLabel getJLabel6() {
if (jLabel6 == null) {
jLabel6 = new JLabel();
jLabel6.setText("复利计算");
}
return jLabel6;
}
private JLabel getJLabel5() {
if (jLabel5 == null) {
jLabel5 = new JLabel();
jLabel5.setText("备注:要求什么哪里就不要你填");
}
return jLabel5;
}
private JLabel getJLabel4() {
if (jLabel4 == null) {
jLabel4 = new JLabel();
jLabel4.setText("要求什么就在哪里就不用写");
}
return jLabel4;
}
private JComboBox getJComboBox0() {
if (jComboBox0 == null) {
jComboBox0 = new JComboBox();
jComboBox0.setModel(new DefaultComboBoxModel(new Object[] { "复利计算", "求本金", "求利息", "求年限" }));
jComboBox0.setDoubleBuffered(false);
jComboBox0.setBorder(null);
}
return jComboBox0;
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("计算");
jButton0.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
jButton0MouseMouseClicked(event);
}
});
}
return jButton0;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("年限");
}
return jLabel2;
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("总额");
}
return jLabel3;
}
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
}
return jTextField3;
}
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
}
return jTextField2;
}
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
}
return jTextField1;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("利息");
}
return jLabel1;
}
private JTextField getJTextField0() {
if (jTextField0 == null) {
jTextField0 = new JTextField();
}
return jTextField0;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("本金");
}
return jLabel0;
}
private static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL + " on this platform:" + e.getMessage());
}
}
/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
public static void main(String[] args) {
installLnF();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
frame.setTitle("MainFrame");
frame.getContentPane().setPreferredSize(frame.getSize());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
Fuli f =new Fuli();
Benjin b =new Benjin();
Lilv l = new Lilv();
Nianxian n = new Nianxian();
private JComboBox jComboBox0;
private JLabel jLabel4;
private JLabel jLabel5;
private JLabel jLabel6;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
private void jButton0MouseMouseClicked(MouseEvent event) {
String p = this.jTextField0.getText();
String i = this.jTextField1.getText();
String year = this.jTextField2.getText();
String sum = this.jTextField3.getText();
if(jComboBox0.getSelectedItem()=="复利计算"){
f.calculate(p, i, year);
this.jTextField3.setText(f.sum);
}
if(jComboBox0.getSelectedItem()=="求本金"){
b.calculate(sum, i, year);
this.jTextField0.setText(b.p);
}
if(jComboBox0.getSelectedItem()=="求利息"){
l.calculate(p, sum, year);
this.jTextField1.setText(l.i);
}
if(jComboBox0.getSelectedItem()=="求年限"){
n.calculate(p, i, sum);
this.jTextField2.setText(n.year);
}
}
}
package com.zhadan.calculate;
import java.text.DecimalFormat;
public class Fuli {
double sum2;
public String sum;
public void calculate(String p2,String i2,String year2){
double p = Double.parseDouble(p2);
double i = Double.parseDouble(i2);
int year = Integer.parseInt(year2);
for(int j=1;j<=year;j++){
p=p+p*i;
}
DecimalFormat df=new DecimalFormat("0.0");
sum2=p;
sum=String.valueOf(df.format(sum2));
}
}
package com.zhadan.calculate;
import java.text.DecimalFormat;
public class Benjin {
double p2;
public String p;
public void calculate(String sum2,String i2,String year2){
double sum = Double.parseDouble(sum2);
double i = Double.parseDouble(i2);
int year = Integer.parseInt(year2);
i=1+i;
for(int j=1;j<=year;j++){
sum=sum/i;
}
DecimalFormat df=new DecimalFormat("0.0");
Math.round(sum);
p2=sum;
p=String.valueOf(df.format(p2));
}
}
package com.zhadan.calculate;
import java.text.DecimalFormat;
public class Lilv {
double i2;
public String i;
public void calculate(String p2,String sum2,String year2){
double p = Double.parseDouble(p2);
double sum = Double.parseDouble(sum2);
double year = Integer.parseInt(year2);
DecimalFormat df=new DecimalFormat("0.0");
i2=Math.pow(sum/p, 1/year)-1;
i=String.valueOf(df.format(i2));
}
}
package com.zhadan.calculate;
public class Nianxian {
int year2=0;
public String year;
public void calculate(String p2,String i2,String sum2){
double p = Double.parseDouble(p2);
double i = Double.parseDouble(i2);
double sum = Double.parseDouble(sum2);
while(p<sum){
for(int j=1;j<100;j++);{
p=p*(1+i);
year2++;
}
}
year=String.valueOf(year2);
System.out.println(year);
}
}
队友谭宇森:http://www.cnblogs.com/dalaotan/p/5392039.html