-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator in GUI.JAVA
More file actions
87 lines (82 loc) · 1.76 KB
/
calculator in GUI.JAVA
File metadata and controls
87 lines (82 loc) · 1.76 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
package calculater;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class program1 extends JFrame implements ActionListener
{
//Frame f;
JFrame f=new JFrame();
Label l1=new Label("enter 1st number");
Label l2=new Label("enter 2nd number");
Label l3=new Label("Result");
TextField t1=new TextField();
TextField t2=new TextField();
TextField t3=new TextField();
Button b1=new Button("Add");
Button b2=new Button("Sub");
Button b3=new Button("Mult");
Button b4=new Button("div");
Button b5=new Button("cancel");
program1()
{
l1.setBounds(50,100,100,20);
l2.setBounds(50,130,100,20);
l3.setBounds(50,170,100,20);
t1.setBounds(200,100,100,20);
t2.setBounds(200,140,100,20);
t3.setBounds(200,180,100,20);
b1.setBounds(10,250,100,20);
b2.setBounds(100,250,100,20);
b3.setBounds(200,250,100,20);
b4.setBounds(300,250,100,20);
b5.setBounds(400,250,100,20);
f.setLayout(null);
f.setVisible(true);
f.setSize(600,400);
f.add(l1);
f.add(t1);
f.add(l2);
f.add(t2);
f.add(b1);
f.add(b2);
f.add(b3);
f.add(b4);
f.add(b5);
f.add(l3);
f.add(t3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
}
public void actionPerformed(ActionEvent ee)
{
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
if(ee.getSource().equals(b1))
{
t3.setText(String.valueOf(n1+n2));
}
if(ee.getSource().equals(b2))
{
t3.setText(String.valueOf(n1-n2));
}
if(ee.getSource().equals(b3))
{
t3.setText(String.valueOf(n1*n2));
}
if(ee.getSource().equals(b4))
{
t3.setText(String.valueOf(n1/n2));
}
if(ee.getSource().equals(b5))
{
System.exit(0);
}
}
public static void main(String [] args)
{
new program1();
}
}