An advanced Sudoku game built with vanilla Java and Swing — no frameworks, no external libraries — that lets you generate and play Sudoku puzzles of any size — not just the traditional 9×9 grid.
Most Sudoku apps hardcode a fixed 9×9 board. This app takes a different approach — it dynamically builds a valid puzzle for any n×n size you choose.
The process works in three stages:
- Generate a solved grid — The app first creates a fully valid, completed
n×nSudoku solution using randomised number placement, ensuring every row, column, and sub-box satisfies Sudoku rules. - Remove random cells — A calculated number of cells are then cleared from the solved grid, leaving behind the clues (pre-filled numbers) and the blanks the player needs to figure out.
- Present the puzzle — The resulting board is handed to the player to solve. If they get stuck, the original solution is still stored and can be revealed on request.
This "solve-first, then hide" approach guarantees that every generated puzzle has exactly one valid solution — the one that was computed at the start.
- Custom grid sizes — Enter any non-prime integer
nto generate ann×nSudoku puzzle - Randomized puzzle generation — Each game produces a unique board
- Interactive GUI — Built with Java Swing; click number buttons to fill in cells
- Eraser tool — 3 uses per game to clear a filled cell
- Answer checker — Verify your solution with a single click
- Reveal answer — If you're stuck, generate the correct solution after checking
- Launch the app — a startup window appears asking for your grid size
n - Enter a non-prime integer (e.g. 4, 6, 9, 16) and click Generate
- The Sudoku board opens with some cells pre-filled and others blank
- Use the number buttons at the bottom to select a value, then click an empty cell to fill it
- Use the ERASER button (up to 3 times) to clear a cell you want to redo
- When done, click Check to see if your solution is correct
- ✅ Correct → You win!
- ❌ Incorrect → Click again to reveal the correct answer
- Click Close to exit the game window
sudukoApp/
├── main.java # Entry point — startup window for choosing grid size
├── UI.java # Main game window — layout, buttons, game flow
├── Grid.java # Sudoku grid rendering and cell interaction
├── Box.java # Manages box/region position indexing
├── Logic.java # Random number generation for puzzle creation
├── FactorGenerator.java # Utility for computing grid factors
└── tst.java # Test/scratch file
- Java JDK 8 or higher
- A Java IDE such as NetBeans (the project was created with NetBeans) or IntelliJ IDEA / Eclipse
git clone https://github.com/ks9205124-cloud/sudukoApp.git
cd sudukoAppjavac -d out *.javajava -cp out suduko.mainNote: The source files belong to the
sudukopackage. Make sure your compilation output directory preserves the package structure.
- The grid size must be a non-prime integer (e.g. 4, 6, 8, 9, 10, 12 …). Entering a prime or invalid value will display an error message in the input field.
- Larger grid sizes (e.g. 16×16) are supported but may require resizing the window for comfortable play.
This project currently uses the default NetBeans license template. See individual source files for details.