- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArea.java
More file actions
Latest commit
123 lines (110 loc) · 4.46 KB
/
Copy pathArea.java
File metadata and controls
123 lines (110 loc) · 4.46 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
importjavax.swing.*;
importjava.awt.event.*;
classAreaextendsJFrameimplementsActionListener {
JButtonclear, circle, rectangle, triangle;
JTextFieldradius, length, breadth, len, bread, height, result;
JLabell, b, h, r, l1, b1, heading, res;
Area() {
super("Area Application");
this.clear = newJButton("CLEAR");
this.circle = newJButton("CIRCLE");
this.rectangle = newJButton("RECTANGLE");
this.triangle = newJButton("TRIANGLE");
this.l = newJLabel("LENGTH");
this.b = newJLabel("BREADTH");
this.h = newJLabel("HEIGHT");
this.r = newJLabel("RADIUS");
this.l1 = newJLabel("LENGTH-TRIANGLE");
this.b1 = newJLabel("BREADTH-TRIANGLE");
this.heading = newJLabel("Area Calculator");
this.res = newJLabel("RESULT");
this.radius = newJTextField(10);
this.length = newJTextField(10);
this.breadth = newJTextField(10);
this.len = newJTextField(10);
this.bread = newJTextField(10);
this.height = newJTextField(10);
this.result = newJTextField(10);
this.add(this.clear);
this.add(this.circle);
this.add(this.rectangle);
this.add(this.triangle);
this.add(this.l);
this.add(this.b);
this.add(this.h);
this.add(this.r);
this.add(this.l1);
this.add(this.b1);
this.add(this.heading);
this.add(this.res);
this.add(this.radius);
this.add(this.length);
this.add(this.breadth);
this.add(this.len);
this.add(this.bread);
this.add(this.height);
this.add(this.result);
this.setLayout(null);
this.heading.setBounds(20, 10, 150, 20);
this.l.setBounds(20, 30, 150, 20);
this.length.setBounds(20, 50, 150, 20);
this.b.setBounds(20, 70, 150, 20);
this.breadth.setBounds(20, 90, 150, 20);
this.r.setBounds(20, 110, 150, 20);
this.radius.setBounds(20, 130, 150, 20);
this.l1.setBounds(20, 150, 150, 20);
this.len.setBounds(20, 170, 150, 20);
this.b1.setBounds(20, 190, 150, 20);
this.bread.setBounds(20, 210, 150, 20);
this.h.setBounds(20, 230, 150, 20);
this.height.setBounds(20, 250, 150, 20);
this.res.setBounds(20, 270, 150, 20);
this.result.setBounds(20, 290, 150, 20);
this.clear.setBounds(200, 150, 150, 100);
this.circle.setBounds(350, 150, 150, 100);
this.rectangle.setBounds(500, 150, 150, 100);
this.triangle.setBounds(650, 150, 150, 100);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(500, 300);
this.clear.addActionListener(this);
this.circle.addActionListener(this);
this.rectangle.addActionListener(this);
this.triangle.addActionListener(this);
}
publicvoidactionPerformed(ActionEventae) {
Objectsource = ae.getSource();
doublelen1, bread1, area1, h1, rad;
intlen2, bread2, area;
try {
if (source == this.circle) {
rad = Double.parseDouble(this.radius.getText());
area1 = 3.14 * rad * rad;
this.result.setText(Double.toString(area1));
} elseif (source == this.rectangle) {
len2 = Integer.parseInt(this.length.getText());
bread2 = Integer.parseInt(this.breadth.getText());
area = len2 * bread2;
this.result.setText(Integer.toString(area));
} elseif (source == this.triangle) {
bread1 = Double.parseDouble(this.bread.getText());
h1 = Double.parseDouble(this.height.getText());
area1 = 0.5 * bread1 * h1;
this.result.setText(Double.toString(area1));
} elseif (source == this.clear) {
this.radius.setText("");
this.result.setText("");
this.len.setText("");
this.bread.setText("");
this.length.setText("");
this.breadth.setText("");
this.height.setText("");
}
} catch (Exceptione) {
this.result.setText("Enter valid values");
}
}
publicstaticvoidmain(Stringargs[]) {
Areaa1 = newArea();
}
}