MENU

Calculator

Repository

I developed this calculator application using JavaFX to create a polished, modern desktop utility. Beyond basic arithmetic, the project implements a custom parsing engine capable of handling operator precedence (BODMAS/PEMDAS) and features a dynamic UI with support for light and dark themes. This project was an exercise in bridging complex backend logic with a responsive, user-friendly graphical interface.

Dynamic UI and Theme Management

The user interface is built using JavaFX and styled with CSS to achieve a modern aesthetic. I implemented a robust theme-switching mechanism that allows users to toggle between light and dark modes in real-time. This is achieved by dynamically swapping stylesheet references and updating icon assets without requiring an application restart. The layout uses a VBox and GridPane architecture to ensure responsiveness across different window sizes.

Operator Precedence Logic

The core calculation engine is designed to handle multi-step equations by respecting standard mathematical precedence. Instead of a simple sequential evaluator, I implemented a two-pass algorithm. The first pass handles high-precedence operations (Multiplication and Division), while the second pass processes Addition and Subtraction. This ensures that an expression like 2 + 3 * 4 correctly evaluates to 14 rather than 20.

State-Driven Event Handling

To manage complex user interactions like negation, undo operations, and chained calculations, I used a state-driven approach. Each button interaction updates a central Calculator state object, which then triggers a UI refresh. I mapped operator buttons to their respective symbols using a HashMap, reducing boilerplate code and making the application's action-dispatching logic more maintainable and extensible.

Technical Implementation Details

The application leverages Maven for dependency management and follows a clean MVC-lite architecture. I utilized FXML for the structural layout while maintaining all styling in external CSS files to ensure a clear separation of concerns. This project provided deep insights into JavaFX event loops, regular expression parsing, and the challenges of building a reliable, stateful desktop application.

Try It Out

Download

If you want to try this app out for yourself, click on the download button and install from GitHub.

Video Demonstration

External Media Required

This video requires third-party cookies from YouTube to be displayed. Accepting will enable all external media across the site.