Java Desktop Calculator Series
A professional desktop calculator project built in two versions (Java AWT & Java Swing) demonstrating GUI development, event-driven programming, and stack-based expression evaluation.
Project Overview
This repository highlights the transition from traditional Abstract Window Toolkit (AWT) applications to modern Java Swing architectures. Developed to demonstrate desktop GUI development paradigms in Java, the calculator series progresses from basic arithmetic trigger bindings to complex multi-operator parsing.
Rather than using simple immediate evaluation (where clicking an operator calculates the running total step-by-step), the advanced Swing version features a complete, standalone expression parsing engine allowing users to input complex nested expressions and evaluate them at once.
Java AWT UI
Designed to focus on native operating system GUI components and classic event-driven listeners.
- Basic arithmetic (+, -, *, /)
- Percentage & Square Root tools
- Standard OS window boundaries
Java Swing & Stacks
Migrated to Swing lightweight rendering pipeline with custom styles and full mathematical expressions.
- Stack-based calculation engine
- Proper BODMAS operator precedence
- Custom Dark Mode UI layout
Stack-Based Calculation Engine
To support complex mathematical expressions containing parentheses and multiple operators with varying precedence, the calculator utilizes a stack-based arithmetic parser.
Dual-Stack Evaluation Model
The engine uses two distinct Java stack objects: a Value Stack (to hold operands/numbers) and an Operator Stack (to hold calculation operators like +, -, *, /). When an operator is processed, its priority is compared with the operator currently at the top of the stack to resolve precedence dynamically.
Infix-to-Postfix Parser
Implements standard parsing algorithms (similar to the Shunting-yard algorithm) to parse string expressions. The input formula is tokenized, converting standard infix expressions (e.g., 3 + 5 * 2) into postfix format internally to evaluate multiplication before addition, returning correct results without parenthetical ambiguity.
Input Validation & Sanitization
Ensures mathematical correctness by blocking consecutive operator input, validating parenthetical closures, and outputting clean syntax error prompts if incomplete equations are submitted.
Details
- Type Academic Project
- Category Desktop (Java)
- Status Source Available
- Role Developer