A simple, interactive calculator built using Java Swing. This calculator application allows users to perform basic arithmetic operations
(following BODMAS rules) and includes an interactive GUI interface with buttons and a display area. Users can enter calculations using
both mouse clicks on the buttons and keyboard input (including pressing Enter
for quick calculation).
- Basic Arithmetic Operations: Supports addition, subtraction, multiplication, division, power and squareroot funcionality.
- Keyboard Input: Press
Enter
for calculation, as well as using+
,-
,*
, and/
keys. - Undo Button: Delete the last character of the input, or navigate in the textfield to where you want to delete and delete the character before your caret position.
- Color Customization: Choose a background color for the calculator.
- Error Handling: Displays friendly error messages for invalid operations, such as division by zero.
These instructions will help you set up and run the Java Swing Calculator on your local machine.
Make sure you have the following installed:
- Java Development Kit (JDK): Version 11 or later. You can download it from Oracle's website or OpenJDK.
- Git: To clone the repository. If you don’t have Git, download it from Git’s website.
- An IDE or Text Editor (Optional but recommended): An IDE like IntelliJ IDEA or Eclipse can make it easier to run and test the project.
- Clone the repository:
git clone https://github.com/Optymist/java_calculator.git
- Open the project in your preferred IDE.
- Locate the Calculator.java file.
- Right click and run or press the ▶ button next to the class name.
- Ensure you are in the project directory:
cd ~/java_calculator/calculator
- Compile the program:
javac -d bin src/main/java/org/example/Calculator.java
- Run the program:
java -cp bin org.example.Calculator
- After executing any of these, a window should pop up with the calculator's screen evident.
- Locate the test/java package.
- Right click and run the tests.
- Navigate to the repository:
cd ~/java_calculator/calculator
- Run the tests using Maven:
mvn test
- After executing any of these, the tests should run and should all pass successfully.
I plan to add more advanced features in future versions, including:
- Advanced Functions: Adding support for square roots, trigonometric functions, radians, pi, and more advanced calculation functionality.
- Memory Functions: Include options to store and recall memory values.
- Calculation History: Show previous calculations, allowing users to reference or reuse past results.
- Error Logging: Add a log for errors and warnings that users encounter while using the calculator.
The project is built with:
- Java: Core programming language for the application.
- Java Swing: Used for creating the graphical user interface (GUI).
- JUnit: For unit testing and GUI testing.
Optional:
- Maven or Gradle (if used for managing dependencies or building the project).
This is a personal project that I have implemented for my own growth but if you would like to contribute you can email me at kimlynsmart@gmail.com.