-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextFieldExample.java
105 lines (90 loc) · 2.29 KB
/
TextFieldExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import javax.swing.*;
import java.awt.event.*;
public class TextFieldExample implements ActionListener {
JFrame f = new JFrame("Simple & Compound Interest Rate Calculator");
JTextField t,t2,t3,r,t4;
JButton d,g;
JLabel a,b,j,k,l;
TextFieldExample(){
a = new JLabel("Enter Your name:");
a.setBounds(100, 100, 100, 40);
t = new JTextField("");
t.setBounds(220,100,200,50);
b = new JLabel("Your Amout:");
b.setBounds(100, 200, 100, 40);
t2 = new JTextField("");
t2.setBounds(220,200,200,50);
j = new JLabel("Interest Rate:");
j.setBounds(100, 300, 100, 40);
r = new JTextField();
r.setBounds(220,300,200,50);
k = new JLabel("Time(Years):");
k.setBounds(100, 400, 100, 40);
t4 = new JTextField();
t4.setBounds(220,400,200,50);
l = new JLabel("Total Interest:");
l.setBounds(100, 500, 100, 40);
t3 = new JTextField();
t3.setBounds(220,500,200,50);
t3.setEditable(false);
d = new JButton("Simple");
d.setBounds(220, 640, 100, 40);
g = new JButton("Compound");
g.setBounds(340, 640, 100, 40);
f.add(a);
f.add(b);
f.add(j);
f.add(t);
f.add(l);
f.add(k);
f.add(t4);
f.add(t2);
f.add(t3);
f.add(d);
f.add(g);
f.add(r);
d.addActionListener(this);
g.addActionListener(this);
f.setSize(800,1000);
f.setLayout(null);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
double x,y,z;
try{
String s1=t2.getText();
x=Double.parseDouble(s1);
}
catch(NumberFormatException ex){
t3.setText("Error");
return;
}
try{
String s2=t4.getText();
y=Double.parseDouble(s2);
}
catch(NumberFormatException ex){
t3.setText("Error");
return;
}
try{
String s3=r.getText();
z=Double.parseDouble(s3);
}
catch(NumberFormatException ex){
t3.setText("Error");
return;
}
double c=0;
if(e.getSource()==d){
c=x*y*(z/100);
}
else if(e.getSource()==g){
c= x*(Math.pow((1 + z / 100), y));
}
String result=String.valueOf(c);
t3.setText(result);
}
public static void main(String[] args) {
new TextFieldExample();
} }