├── .classpath
├── .gitignore
├── .project
├── LICENSE
├── README.md
└── src
└── JavaCalculator.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | JavaCalculator
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
19 | 1651830898856
20 |
21 | 30
22 |
23 | org.eclipse.core.resources.regexFilterMatcher
24 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2022, S Sidharth
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
--------------------------------------------------------------------------------
/src/JavaCalculator.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.awt.event.ActionEvent;
3 | import java.awt.event.ActionListener;
4 | import javax.swing.JFrame;
5 | import javax.swing.JButton;
6 | import javax.swing.JLabel;
7 | import javax.swing.SwingConstants;
8 |
9 |
10 |
11 |
12 | public class JavaCalculator implements ActionListener {
13 |
14 | JFrame Frame;
15 | JLabel DisplayLabel;
16 | JButton ButtonAddition, ButtonSubtraction, ButtonMultiplication, ButtonDivision, ButtonEquals, ButtonPoint, ButtonClear;
17 | JButton ButtonZero, ButtonOne, ButtonTwo, ButtonThree, ButtonFour, ButtonFive, ButtonSix, ButtonSeven, ButtonEight, ButtonNine;
18 | boolean IsOperatorClicked=false;
19 | String OldValue;
20 | int OperationNumber=0;
21 | float Result=00;
22 |
23 |
24 | public JavaCalculator() {
25 | Frame=new JFrame("JavaCalcualator by Sidharth");
26 | Frame.setLayout(null);
27 | Frame.setSize(610,680);
28 | Frame.setLocation(750,10);
29 | Frame.setVisible(true);
30 | Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31 | Frame.getContentPane().setBackground(Color.black);
32 |
33 |
34 | DisplayLabel=new JLabel();
35 | DisplayLabel.setBounds(31, 12, 520, 60);
36 | DisplayLabel.setBackground(Color.black);
37 | DisplayLabel.setOpaque(true);
38 | DisplayLabel.setHorizontalAlignment(SwingConstants.RIGHT);
39 | DisplayLabel.setForeground(Color.white);
40 | DisplayLabel.setFont(new Font("Serif", Font.PLAIN, 70));
41 | Frame.add(DisplayLabel);
42 |
43 |
44 | ButtonSeven=new JButton("7");
45 | ButtonSeven.setBounds(31,82, 112, 112);
46 | ButtonSeven.addActionListener(this);
47 | ButtonSeven.setFont(new Font("Serif", Font.BOLD, 50));
48 | ButtonSeven.setBackground(Color.black);
49 | ButtonSeven.setForeground(Color.orange);
50 | Frame.add(ButtonSeven);
51 |
52 | ButtonEight=new JButton("8");
53 | ButtonEight.setBounds(173,82, 112, 112);
54 | ButtonEight.addActionListener(this);
55 | ButtonEight.setFont(new Font("Serif", Font.BOLD, 50));
56 | ButtonEight.setBackground(Color.black);
57 | ButtonEight.setForeground(Color.orange);
58 | Frame.add(ButtonEight);
59 |
60 | ButtonNine=new JButton("9");
61 | ButtonNine.setBounds(315,82, 112, 112);
62 | ButtonNine.addActionListener(this);
63 | ButtonNine.setFont(new Font("Serif", Font.BOLD, 50));
64 | ButtonNine.setBackground(Color.black);
65 | ButtonNine.setForeground(Color.orange);
66 | Frame.add(ButtonNine);
67 |
68 | ButtonAddition=new JButton("+");
69 | ButtonAddition.setBounds(457,203, 112, 90);
70 | ButtonAddition.addActionListener(this);
71 | ButtonAddition.setFont(new Font("Serif", Font.BOLD, 60));
72 | ButtonAddition.setBackground(Color.black);
73 | ButtonAddition.setForeground(Color.green);
74 | Frame.add(ButtonAddition);
75 |
76 | ButtonClear=new JButton("DEL");
77 | ButtonClear.setBounds(457,84, 112, 90);
78 | ButtonClear.addActionListener(this);
79 | ButtonClear.setFont(new Font("Serif", Font.BOLD,35));
80 | ButtonClear.setBackground(Color.black);
81 | ButtonClear.setForeground(Color.green);
82 | Frame.add(ButtonClear);
83 |
84 | ButtonFour=new JButton("4");
85 | ButtonFour.setBounds(31,224, 112, 112);
86 | ButtonFour.addActionListener(this);
87 | ButtonFour.setFont(new Font("Serif", Font.BOLD, 50));
88 | ButtonFour.setBackground(Color.black);
89 | ButtonFour.setForeground(Color.orange);
90 | Frame.add(ButtonFour);
91 |
92 | ButtonFive=new JButton("5");
93 | ButtonFive.setBounds(173,224, 112, 112);
94 | ButtonFive.addActionListener(this);
95 | ButtonFive.setFont(new Font("Serif", Font.BOLD, 50));
96 | ButtonFive.setBackground(Color.black);
97 | ButtonFive.setForeground(Color.orange);
98 | Frame.add(ButtonFive);
99 |
100 | ButtonSix=new JButton("6");
101 | ButtonSix.setBounds(315,224, 112, 112);
102 | ButtonSix.addActionListener(this);
103 | ButtonSix.setFont(new Font("Serif", Font.BOLD, 50));
104 | ButtonSix.setBackground(Color.black);
105 | ButtonSix.setForeground(Color.orange);
106 | Frame.add(ButtonSix);
107 |
108 | ButtonSubtraction=new JButton("-");
109 | ButtonSubtraction.setBounds(457,320, 112, 90);
110 | ButtonSubtraction.addActionListener(this);
111 | ButtonSubtraction.setFont(new Font("Serif", Font.BOLD, 60));
112 | ButtonSubtraction.setBackground(Color.black);
113 | ButtonSubtraction.setForeground(Color.green);
114 | Frame.add(ButtonSubtraction);
115 |
116 | ButtonOne=new JButton("1");
117 | ButtonOne.setBounds(31,366, 112, 112);
118 | ButtonOne.addActionListener(this);
119 | ButtonOne.setFont(new Font("Serif", Font.BOLD, 50));
120 | ButtonOne.setBackground(Color.black);
121 | ButtonOne.setForeground(Color.orange);
122 | Frame.add(ButtonOne);
123 |
124 | ButtonTwo=new JButton("2");
125 | ButtonTwo.setBounds(173,366, 112, 112);
126 | ButtonTwo.addActionListener(this);
127 | ButtonTwo.setFont(new Font("Serif", Font.BOLD, 50));
128 | ButtonTwo.setBackground(Color.black);
129 | ButtonTwo.setForeground(Color.orange);
130 | Frame.add(ButtonTwo);
131 |
132 | ButtonThree=new JButton("3");
133 | ButtonThree.setBounds(315,366, 112, 112);
134 | ButtonThree.addActionListener(this);
135 | ButtonThree.setFont(new Font("Serif", Font.BOLD, 50));
136 | ButtonThree.setBackground(Color.black);
137 | ButtonThree.setForeground(Color.orange);
138 | Frame.add(ButtonThree);
139 |
140 | ButtonEquals=new JButton("=");
141 | ButtonEquals.setBounds(457,550, 112, 70);
142 | ButtonEquals.addActionListener(this);
143 | ButtonEquals.setFont(new Font("Serif", Font.BOLD, 60));
144 | ButtonEquals.setBackground(Color.black);
145 | ButtonEquals.setForeground(Color.green);
146 | Frame.add(ButtonEquals);
147 |
148 | ButtonZero=new JButton("0");
149 | ButtonZero.setBounds(31,508, 112, 112);
150 | ButtonZero.addActionListener(this);
151 | ButtonZero.setFont(new Font("Serif", Font.BOLD, 50));
152 | ButtonZero.setBackground(Color.black);
153 | ButtonZero.setForeground(Color.orange);
154 | Frame.add(ButtonZero);
155 |
156 | ButtonMultiplication=new JButton("X");
157 | ButtonMultiplication.setBounds(173,508, 112, 112);
158 | ButtonMultiplication.addActionListener(this);
159 | ButtonMultiplication.setFont(new Font("Arial", Font.BOLD, 50));
160 | ButtonMultiplication.setBackground(Color.black);
161 | ButtonMultiplication.setForeground(Color.green);
162 | Frame.add(ButtonMultiplication);
163 |
164 | ButtonDivision=new JButton("/");
165 | ButtonDivision.setBounds(315,508, 112, 112);
166 | ButtonDivision.addActionListener(this);
167 | ButtonDivision.setFont(new Font("Serif", Font.BOLD, 70));
168 | ButtonDivision.setBackground(Color.black);
169 | ButtonDivision.setForeground(Color.green);
170 | Frame.add(ButtonDivision);
171 |
172 |
173 | ButtonPoint=new JButton(" .\n ");
174 | ButtonPoint.setBounds(457,435, 112, 90);
175 | ButtonPoint.addActionListener(this);
176 | ButtonPoint.setFont(new Font("Serif", Font.BOLD, 70));
177 | ButtonPoint.setBackground(Color.black);
178 | ButtonPoint.setForeground(Color.green);
179 | Frame.add(ButtonPoint);
180 |
181 |
182 |
183 | }
184 |
185 | public static void main(String args[]) {
186 |
187 | new JavaCalculator();
188 | }
189 |
190 | public void actionPerformed(ActionEvent ScreenAction) {
191 |
192 | if(ScreenAction.getSource()==ButtonSeven) {
193 | if(IsOperatorClicked==true) {
194 | DisplayLabel.setText("7");
195 | IsOperatorClicked=false;
196 | }
197 | else {
198 | DisplayLabel.setText(DisplayLabel.getText()+"7");
199 | }
200 | }
201 | else if(ScreenAction.getSource()==ButtonEight) {
202 | if(IsOperatorClicked==true) {
203 | DisplayLabel.setText("8");
204 | IsOperatorClicked=false;
205 | }
206 | else {
207 | DisplayLabel.setText(DisplayLabel.getText()+"8");
208 | }
209 | }
210 | else if(ScreenAction.getSource()==ButtonNine) {
211 | if(IsOperatorClicked==true) {
212 | DisplayLabel.setText("9");
213 | IsOperatorClicked=false;
214 | }
215 | else {
216 | DisplayLabel.setText(DisplayLabel.getText()+"9");
217 | }
218 | }
219 | else if(ScreenAction.getSource()==ButtonFour) {
220 | if(IsOperatorClicked==true) {
221 | DisplayLabel.setText("4");
222 | IsOperatorClicked=false;
223 | }
224 | else {
225 | DisplayLabel.setText(DisplayLabel.getText()+"4");
226 | }
227 | }
228 | else if(ScreenAction.getSource()==ButtonFive) {
229 | if(IsOperatorClicked==true) {
230 | DisplayLabel.setText("5");
231 | IsOperatorClicked=false;
232 | }
233 | else {
234 | DisplayLabel.setText(DisplayLabel.getText()+"5");
235 | }
236 | }
237 | else if(ScreenAction.getSource()==ButtonSix) {
238 | if(IsOperatorClicked==true) {
239 | DisplayLabel.setText("6");
240 | IsOperatorClicked=false;
241 | }
242 | else {
243 | DisplayLabel.setText(DisplayLabel.getText()+"6");
244 | }
245 | }
246 | else if(ScreenAction.getSource()==ButtonOne) {
247 | if(IsOperatorClicked==true) {
248 | DisplayLabel.setText("1");
249 | IsOperatorClicked=false;
250 | }
251 | else {
252 | DisplayLabel.setText(DisplayLabel.getText()+"1");
253 | }
254 | }
255 | else if(ScreenAction.getSource()==ButtonTwo) {
256 | if(IsOperatorClicked==true) {
257 | DisplayLabel.setText("2");
258 | IsOperatorClicked=false;
259 | }
260 | else {
261 | DisplayLabel.setText(DisplayLabel.getText()+"2");
262 | }
263 | }
264 | else if(ScreenAction.getSource()==ButtonThree) {
265 | if(IsOperatorClicked==true) {
266 | DisplayLabel.setText("3");
267 | IsOperatorClicked=false;
268 | }
269 | else {
270 | DisplayLabel.setText(DisplayLabel.getText()+"3");
271 | }
272 | }
273 | else if(ScreenAction.getSource()==ButtonZero) {
274 | if(IsOperatorClicked==true) {
275 | DisplayLabel.setText("0");
276 | IsOperatorClicked=false;
277 | }
278 | else {
279 | DisplayLabel.setText(DisplayLabel.getText()+"0");
280 | }
281 | }
282 | else if(ScreenAction.getSource()==ButtonPoint) {
283 | DisplayLabel.setText(DisplayLabel.getText()+".");
284 | }
285 | else if(ScreenAction.getSource()==ButtonAddition) {
286 | IsOperatorClicked=true;
287 | OldValue=DisplayLabel.getText();
288 | OperationNumber=1;
289 | }
290 | else if(ScreenAction.getSource()==ButtonSubtraction) {
291 | IsOperatorClicked=true;
292 | OldValue=DisplayLabel.getText();
293 | OperationNumber=2;
294 |
295 | }
296 | else if(ScreenAction.getSource()==ButtonMultiplication) {
297 | IsOperatorClicked=true;
298 | OldValue=DisplayLabel.getText();
299 | OperationNumber=3;
300 | }
301 | else if(ScreenAction.getSource()==ButtonDivision) {
302 | IsOperatorClicked=true;
303 | OldValue=DisplayLabel.getText();
304 | OperationNumber=4;
305 | }
306 | else if(ScreenAction.getSource()==ButtonEquals) {
307 | String NewValue=DisplayLabel.getText();
308 | float OldValueFloat=Float.parseFloat(OldValue);
309 | float NewValueFloat=Float.parseFloat(NewValue);
310 | if(OperationNumber==1) {
311 | Result=OldValueFloat+NewValueFloat;
312 | DisplayLabel.setText(Result+"");
313 | }
314 | else if(OperationNumber==2) {
315 | Result=OldValueFloat-NewValueFloat;
316 | DisplayLabel.setText(Result+"");
317 | }
318 | else if(OperationNumber==3) {
319 | Result=OldValueFloat*NewValueFloat;
320 | DisplayLabel.setText(Result+"");
321 | }
322 | else if(OperationNumber==4) {
323 | Result=OldValueFloat/NewValueFloat;
324 | DisplayLabel.setText(Result+"");
325 | }
326 | }
327 | else {
328 | DisplayLabel.setText("");
329 | }
330 |
331 | }
332 |
333 | }
334 |
--------------------------------------------------------------------------------