Simple scientific calculator implemented in Java using Swing. Demonstrates event handling (ActionListener) and exception handling (try/catch).
Files
Build & Run (command line on Windows)
- Open a terminal in the project root
d:\hobby\calculator. - Compile:
javac -d out src\Calculator.java- Run:
java -cp out CalculatorUsage
- Click number buttons to enter values.
- Use
+,-,*,/for arithmetic; press=to compute. - Scientific functions (
sin,cos,tan,log,sqrt,x^2,pi) apply immediately to the shown value. ACclears all state.
Exception handling
- Division by zero shows: "Error: Division by zero is not allowed"
- Invalid or empty input shows: "Invalid Input"
- Unexpected errors show a generic message; the app does not crash.
Notes
- Angles for trigonometric functions are interpreted in degrees.
- This is a compact educational example intended for learning event and exception handling.