Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Swing Calculator

Java GUI License: MIT

A lightweight desktop calculator built with Java Swing. The project demonstrates graphical user-interface construction, event-driven programming, input parsing, and basic error handling in a compact Java application.

Features

  • Addition, subtraction, multiplication, and division
  • Button-based input for digits and operators
  • Clear (C) and calculate (=) actions
  • Support for multi-digit values
  • Decimal results through double arithmetic
  • Validation for malformed expressions
  • Explicit handling of division by zero
  • Swing event handling through a shared ActionListener

Technologies

  • Java
  • Java Swing
  • AWT event handling

No third-party dependencies are required.

Requirements

  • JDK 8 or newer
  • A desktop environment capable of displaying Swing applications

Run locally

Clone the repository:

git clone https://github.com/andreiboscu/java-swing-calculator.git
cd java-swing-calculator

Compile the application:

javac -d out Calculator.java

Run it:

java -cp out lab7.Calculator

You can also import Calculator.java into IntelliJ IDEA, Eclipse, or another Java IDE and run the main method.

Usage

Enter an expression using the calculator buttons, then press =.

Example:

123 + 7

The calculator expects one operation at a time in the form:

number operator number

Press C to clear the display. Invalid input produces an error message, while division by zero is reported separately.

Project structure

.
├── Calculator.java
├── LICENSE
├── README.md
└── .gitignore

Concepts demonstrated

Java · Swing · GUI Development · ActionListener · Event-Driven Programming · Input Validation · Exception Handling

Possible future improvements

  • Add decimal-point and backspace buttons
  • Support chained calculations
  • Improve keyboard input
  • Use layout managers for responsive resizing
  • Separate calculation logic from the graphical interface
  • Add automated unit tests
  • Package the application as an executable JAR

License

This project is available under the MIT License.

About

Java Swing desktop calculator featuring basic arithmetic operations, button-based input, validation, and division-by-zero handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages