A simple calculator application built in Java using Swing and AWT for the graphical user interface. This calculator mimics the functionality of a basic physical calculator and supports standard arithmetic operations.
- Addition, Subtraction, Multiplication, Division
- Square root calculation
- Percentage operation
- Positive/Negative toggle (
+/-) - Clear button (
AC) - Decimal support
- Java 8 or higher
- Swing
- AWT
- The calculator GUI is built with
JFrame,JPanel,JButton, andJLabel. - All button events are handled using
ActionListener. - Input is taken via number and operator buttons.
- Upon pressing
=, the selected operation is performed using the stored operands and operator. - The result is displayed with formatting (e.g., whole numbers shown without
.0).
- Clone the repository or download the code.
- Navigate to the project folder.
- Compile the Java file:
javac Calculator.java
- Run the program:
java Calculator
- Enter
12, press+, then8, then=, and you’ll get20. - Press
√, enter a number like25, then=, and it will return5. - Use
%to find percentages, and+/-to toggle the sign.
- Code uses
==instead of.equals()for string comparisons (not recommended in Java). - Square root function only works in a specific input sequence.
- No error handling for divide-by-zero or malformed inputs yet.
- Replace
==with.equals()for correct string comparison. - Add memory functions (M+, M-, MR).
- Improve layout responsiveness for different window sizes.
- Add unit tests for arithmetic operations.
This project is open-source and available under the
Developed by \T S BHUVANESHWAR. Contributions and suggestions are welcome!