Skip to content

Lmg15186/java-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

Java Calculator with GUI

A simple desktop calculator built in Java with Swing, supporting the four basic arithmetic operations through an interactive graphical interface.

Overview

Single-window application that takes two numeric inputs and performs addition, subtraction, multiplication or division based on the user's selection. Includes input validation, error handling for invalid numbers, and a guard against division by zero.

Features

  • Two input fields for the operands and one read-only field for the result
  • Four operation buttons: Add, Subtract, Multiply, Divide
  • Clear button to reset all fields
  • Exit button to close the application
  • Division-by-zero protection with a user-facing error dialog
  • Input validation — non-numeric values trigger an error message instead of crashing

Technical Details

Aspect Implementation
Framework Java Swing (JFrame, JTextField, JButton, JLabel, JOptionPane)
Layout FlowLayout for simple, predictable component arrangement
Event Handling Implements ActionListener to dispatch button events
Threading Uses SwingUtilities.invokeLater to ensure the GUI runs on the Event Dispatch Thread
Error Handling try/catch on NumberFormatException plus an explicit zero-division check

How to Run

  1. Make sure you have Java JDK installed (version 8 or higher)
  2. Compile the source file:
   javac Calculation.java
  1. Run the application:
   java Calculation

What I Learned

  • Building event-driven Java GUIs with Swing
  • Handling user input safely with exception-based validation
  • Ensuring the UI thread runs properly via the Event Dispatch Thread
  • Designing clean user feedback with dialog boxes for error states

Part of my IT learning journey at the Academy of Interactive Technology (AIT) — see more at github.com/Lmg15186

About

Java desktop calculator with Swing GUI — basic arithmetic, input validation and division-by-zero protection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages