-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame3.java
65 lines (54 loc) · 1.14 KB
/
frame3.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
import java.awt.event.*;
import java.awt.*;
class frame3 extends Frame implements ActionListener
{
Label l1,l2,l3;
TextField t1,t2,t3;
Button b1,b2;
frame3(String s)
{
super(s);
l1 = new Label("First Number");
l2 = new Label("Second Number");
l3 = new Label("Result");
t1 = new TextField(10);
t2 = new TextField(10);
t3 = new TextField(10);
b1 = new Button("SUM");
b2 = new Button("MUL");
b1.addActionListener(this);
b2.addActionListener(this);
setLayout(new FlowLayout());
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(b2);
}
public void actionPerformed(ActionEvent ae)
{
int n1 = Integer.parseInt(t1.getText());
int n2 = Integer.parseInt(t2.getText());
if(ae.getSource()==b1)
{
int sum=n1+n2;
t3.setText(""+sum);
}
else
{
int mul=n1*n2;
t3.setText(""+mul);
}
t3.setEditable(false);
}
public static void main(String args[])
{
frame3 f1= new frame3("Application");
f1.setLocation(100,100);
f1.setSize(300,300);
f1.setVisible(true);
}
}