Lab 8
[valid 2025-2026]
Graphical User Interfaces
Create a desktop Java application with a graphical user interface that allows a user to create a maze manually or automatically.
The maze must be represented as a rectangular grid of cells.
Each cell should store at least its row and column and whether each wall exists: top, right, bottom, left.
You may use either Swing+Java2D or JavaFX.
The main specifications of the application are:
Compulsory (1p)
Create the following components:
- The main frame of the application.
- A configuration panel for introducing parameters - such as maze dimensions, and a button to draw the cells of the maze (with all the walls in place) .
It must contain at least one label, one input component and one button.
- A canvas (drawing panel) for drawing the maze.
Each cell should be drawn as a square (choose your color). Walls should be drawn as lines around the square.
This panel must be placed in the center part of the frame.
- A control panel for managing the state of the maze.
This panel will contain the buttons: Create, Reset and Exit, etc. and it will be placed at the bottom part of the frame.
The Create button will randomly remove walls of the cells.
Homework (2p)
- The user must be able to manually edit the maze by clicking a cell wall to toggle it on/off.
- Add a button to validate whether the maze is traversable from a start cell to an end cell.
- Export the image of the maze into a PNG file.
- Use object serialization in order to save and restore the current status of the maze.
Bonus (2p)
- Implement an algorithm to generate a maze automatically.
The generated maze should contain exactly one connected component, have no isolated areas, have a unique path between any two cells.
You may use Recursive Backtracking to build a perfect maze, by performing a depth-first traversal of the grid,
or any other algorithm (Prim, Kruskal, Recursive Division, etc.)
Prove that the generated maze is valid.
- The algorithm should dynamically update the GUI during execution, providing an animated generation process with adjustable speed control.
Resources
Objectives
- Get familiar with the basic elements of design involved in creating a GUI.
- Understand the concepts of component, container, layout manager.
- Get acquainted with various libraries for creating a GUI application, such as AWT, Swing, SWT, Java FX.
- Write event listeners to handle events.
- Understand how Swing components are painted.
- Create custom components using Java2D that coexist with standard Swing components.
- Understand the concept of graphic context.
- Get familiar with Java2D basic geometric primitives, use colors, fonts, images
- Get acquainted with JavaFX technology and understand the differences between Swing and JavaFX.