CS35: Homework #5

CS35 Spring 2001

Homework 5: A GUI front-end to the Maze Program
Due: Friday, March 8th before 5pm

CONTENTS

You should work by yourself on this assignment.


PROBLEM DESCRIPTION

For this assignment you will build a GUI (graphical user interface) front-end to the maze program you wrote for Homework #4.

Your GUI program will display an array of buttons, each representing a position in the maze. You may use a fixed-size maze for this program (i.e. your GUI maze program always creates a maze of the same mxn dimensions). However, it should create a maze that is at least 10x10. The start and end positions should be visually distinct from the other buttons in the array. Each maze button should be designed such that a user can add or remove a wall from the (i,j) location in the maze by clicking on that maze button.

In addition to the main maze grid, the GUI has a text area for displaying the results of the path search, and a set of buttons for the following actions:

  1. Clear all the walls from the maze
  2. Create a random maze
  3. Find a path through the maze using a stack and display it
  4. Find a path through the maze using a queue and display it
You may include any additional functionality that you wish in your maze GUI.

As the user selects different options, the text display should display appropriate messages. For example, if the user selects a "Find a Path" button, then the text display should provide information about the path search (either that there is no path through the maze, or the length of the found path).

As the user makes changes to the existing maze, think about what in the display needs to be changed. For example, if the GUI is currently displaying the results of a path search, and the user clicks on a maze block to add a new wall, then the text message and the path that are displayed are no longer valid for this changed maze.


GETTING STARTED

You should begin by reviewing the example GUI programs we provided in class. You can copy the example GUI programs from: /home/newhall/public/cs35/week5/. Also, if you'd like more information about Swing, consult the Java
Swing Tutorial and the Java API documentation for the Swing classes.

Once you have a basic idea of how to use Swing. Start implementing a class that will be a front-end to the Maze class you wrote for Homework #4. You will most likely want to use the BorderLayout manager for laying out the three highest level components: the maze grid, the text display, and the set of maze action buttons. Within each of these, you may want to use other layout managers. For example, the maze grid of buttons is probably best constructed using the GridLayout manager.

A good starting place is to try to create the grid of buttons, each one corresponding to an underlying (i,j) position in the maze. You need to provide a way to communicate between the buttons depicting the maze and the maze itself. You may want to create a new MazeButton class to store the button and any other information you need.

Once you get the correct grid layout, test that clicking on a block in the grid sets/clears the corresponding (i,j) element in the maze and that the visual representation of the block changes when it is set/cleared. Next add support for the start and end blocks in the maze. Make sure that a user cannot put a wall block in either of these positions. Next, add the "Clear Maze" button checking that it correctly sets all the underlying maze (i,j) elements to 0. And continue adding functionality one piece at a time.

If you did not successfully complete homework #4, then you can start with my solution which is available here.

In addition, you can try running my solution in:


EXTRA CREDIT

Once you get the initial program to work, you can add the following to your program to receive extra credit points on this assignment:

HAND IN

Using cs35handin, hand in a single tar file containing:
  1. All Project 5 .java files necessary for compiling your code (include any of the classes that we give you that you use in your solution).
  2. A Makefile for building your code
  3. A README file with:
    1. Your name
    2. The name of the class containing your main method
    3. Whether or not you completed the extra credit part of the assignment