Back to Projects

Accurate Guesser

Java Swing number guessing game demonstrating event-driven UI patterns.

JavaSwingMVCEvent-Driven

Interactive Demo

Guess the Number (1-100)Attempts: 0

Game State Machine

INITIAL
PLAYING
FINISHED

Explicit states prevent edge cases like submitting after winning

MVC Architecture

GameEngine
Core game logic: random number, guess validation, scoring, state transitions
GameUI (JFrame)
Swing components: input fields, buttons, feedback labels, layout management
Event Handlers
ActionListeners connecting UI actions to game logic callbacks

Key Learnings

Event-Driven Architecture
Loose coupling through listeners. Callback-based control flow applicable to React, Vue.
State Management
Without explicit states, edge cases emerge. Manual tracking doesn't scale to complex apps.
Separation of Concerns
Mixing UI with logic creates brittle code. Refactoring to MVC enabled independent testing.
Defense in Depth Validation
UI-level (DocumentFilter), app-level (range), domain-level (state). Each catches different failures.

Design Decisions

Swing over JavaFX
Maturity and extensive documentation. Ideal for learning event-driven fundamentals without framework abstractions.
Explicit State Machine
INITIAL → PLAYING → FINISHED prevents invalid operations. Makes transitions explicit and testable.
UI-Layer Input Validation
DocumentFilter for numeric input provides immediate feedback while GameEngine handles business rules.
Modal Dialogs for State Changes
JOptionPane for win/loss notifications creates clear breakpoints. Prevents accidental resets.
Java
Language
Swing
UI Framework
3
Game States
MVC
Architecture
"Simple concepts can teach foundational programming principles that scale to complex applications."
Lightweight demo of event-driven desktop UI