CS35: Homework #5
You should work by yourself on this assignment.
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:
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.
/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:
Only try the extra credit part after you have completed the regular hw#5 assignment. In addition, you should make a copy of your hw#5 solution so that you have a working correct version before you try adding the animation part.