-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventHandle.java
81 lines (73 loc) · 1.64 KB
/
eventHandle.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class eventHandle implements ActionListener
{
JFrame jf=null;
JButton jb1=null,jb2=null,jb3=null;
JTextField t1=null,t2=null,t3=null;
JLabel l1=null,l2=null,l3=null;
int res;
eventHandle()
{
jf=new JFrame("CALCULATOR");
jf.setSize(300,250);
jf.setLayout(null);
jf.setVisible(true);
jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
l1=new JLabel("Enter no.1:");
l1.setBounds(20,20,100,30);
jf.add(l1);
t1=new JTextField();
t1.setBounds(130,20,100,30);
jf.add(t1);
l2=new JLabel("Enter no.2:");
l2.setBounds(20,60,100,30);
jf.add(l2);
t2=new JTextField();
t2.setBounds(130,60,100,30);
jf.add(t2);
jb1=new JButton("ADD");
jb1.setBounds(20,100,100,50);
jf.add(jb1);
jb1.addActionListener(this);
jb2=new JButton("SUB");
jb2.setBounds(130,100,100,50);
jf.add(jb2);
jb2.addActionListener(this);
l3=new JLabel("RESULT:");
l3.setBounds(20,160,100,30);
jf.add(l3);
t3=new JTextField();
t3.setBounds(130,160,100,30);
t3.setEditable(false);
jf.add(t3);
jb3=new JButton("CLEAR");
jb3.setBounds(20,200,100,50);
jf.add(jb3);
jb3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==jb1)
{
res=(Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText()));
t3.setText(""+res);
}
else if(ae.getSource()==jb2)
{
res=(Integer.parseInt(t1.getText())-Integer.parseInt(t2.getText()));
t3.setText(""+res);
}
else if(ae.getSource()==jb3)
{
t1.setText("");
t2.setText("");
t3.setText("");
}
}
public static void main(String args[])
{
new eventHandle();
}
}