-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCAlci.txt
71 lines (60 loc) · 1.45 KB
/
CAlci.txt
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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//suraj
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Calci extends JFrame implements ActionListener {
//sueaj
JLabel l1,l2,l3,l4;
JTextField t1,t2;
JButton b1,b2;
Calci()
{
l1=new JLabel("Calculator");
l2=new JLabel("First Number");
l3=new JLabel("Second Number");
l4=new JLabel();
t1=new JTextField();
t2=new JTextField();
b1=new JButton("ADD");
b2=new JButton("SUB");
l1.setBounds(300,50,500,60);
l2.setBounds(80,150,300,60);
l3.setBounds(80,250,300,60);
l4.setBounds(200,400,300,60);
t1.setBounds(450,150,300,60);
t2.setBounds(450,250,300,60);
b1.setBounds(100,450,200,60);
b2.setBounds(200,450,200,60);
add(l1);add(l2);add(l3);add(l4);
add(t1);add(t2);add(b1);add(b2);
setTitle("Calculator");
setVisible(true);
setLayout(null);
b1.addActionListener(this);
b2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae) {
// TODO Auto-generated method stub
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
String s=ae.getActionCommand();
if(s.equals("ADD"))
{
int ans=n1+n2;
l4.setText("Result = "+ans);
}
else
{
int sub=n1-n2;
l4.setText("Result = "+sub);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Calci ob=new Calci();
}
}