The code is as follows:
Import Java.awt.Container;
Import Java.awt.Graphics;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import java.awt.event.ItemEvent;
Import Java.awt.event.ItemListener;
Import Javax.swing.JButton;
Import Javax.swing.JComboBox;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JTextField;
public class main extends JFrame implements ActionListener, ItemListener {
Private String msg[] = {"Compound interest Calculation", "simple Interest Calculation", "Principal calculation", "seek term", "seek interest rate", "Investment calculation"};
Graphics G;
Private JButton Jbfind = new JButton ("confirmation");
Private JButton jbclearmsg = new JButton ("clear Information");
Private Container con;
Private jcombobox<object> Jcbstart;
Private jcombobox<object> jcbend;
JTextField JP = new JTextField ();
JTextField ji = new JTextField ();
JTextField JN = new JTextField ();
JTextField JM = new JTextField ("1");
JTextField JF = new JTextField ();
JLabel J1 = new JLabel ("principal");
JLabel J2 = new JLabel ("interest rate");
JLabel J3 = new JLabel ("term");
JLabel J4 = new JLabel ("Times");
JLabel J5 = new JLabel ("Final value");
JLabel ti = new JLabel ("Compounding Calculator");
/**
* @param args
*/
Public Main () {
con = This.getcontentpane ();
Selection box
Jcbstart = new jcombobox<object> (msg);
Jcbstart.seteditable (false);//Non-editable
Jcbstart.setbounds (10, 170, 135, 30);
Add a listener to a selection box
Jcbstart.additemlistener (this);
Jcbend.additemlistener (this);
button position, size
Jbfind.setbounds (220, 420, 90, 30);
Jbclearmsg.setbounds (320, 420, 90, 30);
Add an Action listener
Jbfind.addactionlistener (this);
Jbclearmsg.addactionlistener (this);
Text and display panel
Jp.setbounds (220, 170, 220, 30);
Ji.setbounds (220, 220, 220, 30);
Jn.setbounds (220, 270, 220, 30);
Jm.setbounds (220, 320, 220, 30);
Jf.setbounds (220, 370, 220, 30);
J1.setbounds (180, 170, 30, 30);
J2.setbounds (180, 220, 30, 30);
J3.setbounds (180, 270, 30, 30);
J4.setbounds (180, 320, 30, 30);
J5.setbounds (180, 370, 30, 30);
Ti.setbounds (300, 50, 100, 100);
Display information
Setting up containers
Con.setlayout (NULL);
Con.setsize (600, 600);
Con.setlocation (0, 0);
Add components to a container
Con.add (Jcbstart);
Con.add (Jbfind);
Con.add (JBCLEARMSG);
Con.add (JF);
Con.add (JI);
Con.add (JM);
Con.add (JN);
Con.add (JP);
Con.add (J1);
Con.add (J2);
Con.add (J3);
Con.add (J4);
Con.add (J5);
Con.add (TI);
This.setsize (600, 600);
This.setlocation (300, 300);
This.setresizable (FALSE); Form size is not variable
This.setdefaultcloseoperation (jframe.exit_on_close);//Close the form end program
This.setvisible (TRUE);//display form;
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
New Main ();
}
@Override
public void actionperformed (ActionEvent e) {
TODO auto-generated Method Stub
if (E.getactioncommand (). Equals ("confirm")) {
Double p=0;
Double i=0;
Double n=0;
Double m=0;
Double f=0;
String select = (String) jcbstart.getselecteditem ();
if (select = = "Compound calculation") {
P = double.valueof (Jp.gettext (). toString ()). Doublevalue ();
i = double.valueof (Ji.gettext (). toString ()). Doublevalue ();
n = double.valueof (Jn.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
F = P * (Math.pow ((1 + i/m), n * m));
Jf.settext (double.tostring (F));
} else if (select = = "Simple Interest Calculation") {
P = double.valueof (Jp.gettext (). toString ()). Doublevalue ();
i = double.valueof (Ji.gettext (). toString ()). Doublevalue ();
n = double.valueof (Jn.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
F = P * (1 + i * N);
Jf.settext (double.tostring (F));
} else if (select = = "Principal calculation") {
i = double.valueof (Ji.gettext (). toString ()). Doublevalue ();
n = double.valueof (Jn.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
F = double.valueof (Jf.gettext (). toString ()). Doublevalue ();
P = F/math.pow ((1 + i), n);
Jp.settext (double.tostring (P));
} else if (select = = "seek term") {
P = double.valueof (Jp.gettext (). toString ()). Doublevalue ();
i = double.valueof (Ji.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
F = double.valueof (Jf.gettext (). toString ()). Doublevalue ();
N=math.log ((double) (f/p))/(Math.log ((double) (1+i));
Jn.settext (double.tostring (n));
} else if (select = = "seek interest rate") {
P = double.valueof (Jp.gettext (). toString ()). Doublevalue ();
n = double.valueof (Jn.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
F = double.valueof (Jf.gettext (). toString ()). Doublevalue ();
i = (Math.pow (f/p, 1.0/n))-1;
Ji.settext (double.tostring (i));
} else if (select = = "Investment calculation") {
P = double.valueof (Jp.gettext (). toString ()). Doublevalue ();
i = double.valueof (Ji.gettext (). toString ()). Doublevalue ();
n = double.valueof (Jn.gettext (). toString ()). Doublevalue ();
m = double.valueof (Jm.gettext (). toString ()). Doublevalue ();
for (int j = 0; J < N*m; J + +) {
p = p * (1 + i);
}
F = P;
Jf.settext (double.tostring (F));
}
}
else if (E.getactioncommand (). Equals ("purge Information")) {
Jf.settext ("");
Jp.settext ("");
Ji.settext ("");
Jn.settext ("");
Jm.settext ("1");
}
}
@Override
public void itemstatechanged (ItemEvent e) {
TODO auto-generated Method Stub
}
}
Operation Result:
< reprint please indicate the source and attach the link to this page, thank you >
Software Engineering---Compounding 6.0