This is a simple calculator application built using Java and Swing. It provides basic arithmetic operations such as addition, subtraction, multiplication, and division. The interface is designed to be user-friendly with an aesthetic appearance.
- Basic Arithmetic Operations: Perform addition, subtraction, multiplication, and division.
- Clear and Backspace Functions: Clear the input field or remove the last character.
- Decimal Point: Support for decimal point calculations.
- Error Handling: Inform users about invalid inputs or division by zero.
- JDK 8 or higher installed on your machine.
- An IDE or text editor (such as IntelliJ IDEA, Eclipse, or VS Code) to run and modify the code.
- Basic understanding of Java and Swing.
-
Clone the Repository: Clone this repository to your local machine using the following command:
git clone https://github.com/asifahamed11/Java-Swing-Calculator.git
-
Navigate to the Project Directory:
cd Java-Swing-Calculator -
Compile and Run the Application: Open the project in your preferred IDE and run the
Appclass.Alternatively, you can compile and run the application using the command line:
javac App.java java App
The main components of the code are:
- Class Declaration: The
Appclass extendsJFrameand implementsActionListener. - User Interface Setup: The constructor
App()sets up the user interface, including buttons and the text field. - Event Handling: The
actionPerformedmethod handles the button click events to perform arithmetic operations and other functionalities. - Error Handling: The
try-catchblocks handle potential errors like invalid inputs and division by zero.
- Launching the Application: Run the
Appclass to launch the calculator. - Input Numbers and Operations: Click on the buttons to input numbers and select operations.
- Get Results: Press the
=button to get the result of the operation. - Clear or Backspace: Use the
Cbutton to clear the input or theBackbutton to delete the last character.
If you want to contribute to this project, follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit them (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need for a simple and functional calculator.
- Special thanks to the Java and Swing documentation.
