-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullCal.java
153 lines (150 loc) · 2.86 KB
/
FullCal.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class ex implements ActionListener
{
JFrame jf;
JTextField tf1;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16;
String s1,s2,s4;
int x,y,z;
int sum;
ex()
{
jf= new JFrame("GUI");
jf.setVisible(true);
jf.setSize(500,500);
jf.setLayout(new FlowLayout());
tf1=new JTextField(20);
b1= new JButton("AC");
b2= new JButton("=");
b3= new JButton("+");
b4= new JButton("-");
b5= new JButton("*");
b6= new JButton("/");
b7= new JButton("1");
b8= new JButton("2");
b9= new JButton("3");
b10= new JButton("4");
b11= new JButton("5");
b12= new JButton("6");
b13= new JButton("7");
b14= new JButton("8");
b15= new JButton("9");
b16= new JButton("0");
jf.add(tf1);
jf.add(b1);
jf.add(b2);
jf.add(b3);
jf.add(b4);
jf.add(b5);
jf.add(b6);
jf.add(b7);
jf.add(b8);
jf.add(b9);
jf.add(b10);
jf.add(b11);
jf.add(b12);
jf.add(b13);
jf.add(b14);
jf.add(b15);
jf.add(b16);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String s3="";
JButton jb1,jb2;
Object o1=ae.getSource();
jb1=(JButton)o1;
if(b7==jb1)
tf1.setText(tf1.getText()+"1");
else if(b8==jb1)
tf1.setText(tf1.getText()+"2");
else if(b9==jb1)
tf1.setText(tf1.getText()+"3");
else if(b10==jb1)
tf1.setText(tf1.getText()+"4");
else if(b11==jb1)
tf1.setText(tf1.getText()+"5");
else if(b12==jb1)
tf1.setText(tf1.getText()+"6");
else if(b13==jb1)
tf1.setText(tf1.getText()+"7");
else if(b14==jb1)
tf1.setText(tf1.getText()+"8");
else if(b15==jb1)
tf1.setText(tf1.getText()+"9");
else if(b16==jb1)
tf1.setText(tf1.getText()+"0");
else if(b3==jb1)
{
s1=tf1.getText();
tf1.setText("");
s4="+";
}
else if(b4==jb1)
{
s1=tf1.getText();
tf1.setText("");
s4="-";
}
else if(b5==jb1)
{
s1=tf1.getText();
tf1.setText("");
s4="*";
}
else if(b6==jb1)
{
s1=tf1.getText();
tf1.setText("");
s4="/";
}
else if(b1==jb1)
{
s1="";
s2="";
z=0;
tf1.setText("");
}
else if(b2==jb1)
{
s2=tf1.getText();
y=Integer.parseInt(s2);
x=Integer.parseInt(s1);
if(s4=="+")
z=x+y;
else if(s4=="-")
z=x-y;
else if(s4=="*")
z=x*y;
else if(s4=="/")
z=x/y;
s3= String.valueOf(z);
tf1.setText(s3);
}
}
}
class FullCal
{
public static void main(String args[])
{
ex e= new ex();
}
}