This is a simple calculator application built using Java Swing. The calculator can perform basic arithmetic operations such as addition, subtraction, multiplication, and division. It also logs operations to a file.
- Basic arithmetic operations: addition, subtraction, multiplication, and division.
- Logs operations to a file (
log.txt
). - Simple and intuitive GUI built using Java Swing.
- Java Development Kit (JDK) installed on your machine. You can download it from here.
-
Clone the repository or download the source code.
git clone https://github.com/maryamjbr/simple-calculator.git cd simple-calculator
-
Compile the Java source file.
javac calculator.java
-
Run the compiled Java program.
java calculator
- Numbers: Click on the number buttons (0-9) to input numbers.
- Operations: Click on the operation buttons (
+
,-
,*
,/
) to perform arithmetic operations. - Decimal Point: Click on the
.
button to add a decimal point. - Equals: Click on the
=
button to compute the result of the operation. - Clear: Click on the
clear
button to reset the input fields. - Log: Click on the
log
button to print the log of operations to the console.
- Main Class: The
calculator
class contains the main method and the GUI components. - Method: The
answer
method computes the result of the arithmetic operation.
To add two numbers:
- Click on
2
. - Click on
+
. - Click on
3
. - Click on
=
.
The result (5
) will be displayed in the text field.
All operations are logged in the log.txt
file. You can view the log by clicking the log
button, which will print the log to the console.