A modern calculator with a polished interface, written in JavaFX. It supports keyboard and mouse input, features a dark theme, and follows a professional architecture.
- Basic operations: addition, subtraction, multiplication, division
- Additional functions: percentage (%), sign toggle (±), clear (C)
- Keyboard control: full support for keyboard and Numpad input
- Error handling: division by zero, invalid input
- Correct rounding: automatic removal of trailing zeros
- Dark theme: modern, minimalist design
- Animations: hover and press effects
- Responsive layout: fixed size of 400×600 px
- Professional color scheme: orange operators, gray digits
- Mouse: click all buttons
- Keyboard: digits, Enter, Escape, Backspace
- Numpad: full numeric keypad support
- Keyboard shortcuts:
Enteror=— calculateEscapeorDelete— clearBackspace— delete a characterShift + =— plus sign
calculator/
├── src/main/java/ru/levitsky/calculator/
│ ├── Calculator.java # Main application class
│ ├── constants/
│ │ ├── CalculatorConstants.java # Mathematical constants
│ │ ├── UIConstants.java # Colors and UI constants
│ │ └── UIStyleConstants.java # Styles and dimensions
│ └── util/
│ └── Utils.java # Helper utilities
├── pom.xml # Maven configuration
└── README.md # Documentation
- Java 25 (JDK 25 or higher)
- JavaFX SDK 21.0.6 (automatically downloaded via Maven)
- Maven 3.8+
- Clone the repository
- Open the project in your IDE
- Ensure JavaFX SDK is configured
- Run
Calculator.java
mvn clean compile
mvn javafx:run<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>21</version>
</dependency>
</dependencies>1. Enter the first number (e.g., 123.45)
2. Press an operator (+, -, ×, ÷)
3. Enter the second number (e.g., 67.89)
4. Press = or Enter to get the result
- Decimal point: automatically added only once
- Clear:
Cresets all calculations - Sign toggle:
±inverts the sign of the current number - Percentage:
%divides the number by 100
The calculator has been tested with the following scenarios:
- Basic arithmetic operations
- Division by zero (shows an error message)
- Decimal number handling
- Keyboard input
- Large number processing
- Correct rounding behavior
- Calculator.java: controller and view
- Constants: separate classes for UI and logic
- Utilities: reusable helper functions
// Two-level event handling system
addEventFilter(KeyEvent.KEY_TYPED, this::handleKeyTyped); // Typed characters
addEventFilter(KeyEvent.KEY_PRESSED, this::handleSpecialKeys); // Special keysprivate double num1, num2; // Operands
private String operator; // Current operation
private boolean startNewNumber; // Start new number flag
private boolean calculationDone; // Calculation completed flag- Calculation history
- Memory buttons (M+, M-, MR, MC)
- Ctrl+C / Ctrl+V copy & paste support
- Scientific mode (sin, cos, sqrt, powers)
- Unit converter
- Light / dark theme toggle
- Expression support
Pull requests are welcome! For major changes, please open an Issue first to discuss your ideas.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
Levitsky
- GitHub: Anatoliy Levitsky
- Project: JavaFX Calculator
