Homework 5 - Swing and GUIs


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]

Reading: Chapters 8 and 9.

Due: At 8:00am, Friday February 23, 2001, submit is turned off automatically. Work turned in after that time will not be accepted for grading.

Program Description

Use the class GameBoard as a starting point and create a GUI for the Predator-Prey simulation in Section 7.8. Use a 10 x 10 square to represent each cell in the world. Fill the square with green for grass, red for fox, and white for rabbits. The user can change a square to the "current life form" by clicking on a square. The "current life form" is selected from a menu. Control the progress of time with a button. Each click of the button should advance time one generation. You can use a BorderLayout, with the world in the center, and the Next generation button on a border.

The menu bar should include a File menu with the option Exit, and a LifeForm menu with the options Empty, Grass, Fox, and Rabbit.

When the program starts up, it should read the initial configuration of the world from the console. The startup file will consist of one integer, size, followed by size lines of size characters. (The following was changed on 2-15-01. If you already implemented input using the earlier specification of e, g, f, or r, then you may use it but I would prefer it if you wouldn't mind making the minor change as follows.) The characters will be one of ., G, F, or R (I find this makes the input file much more pleasing to the human eye). There will be no white space between the characters on a single line, and there will be one line of charactes for each row of the world. Here is a sample input file.

10
..........
..........
..........
..........
...GGG....
...FFF....
....RRG...
..........
..........
..........

Be sure and use the swing based GameBoard example (a slight modification of the example in section 9.7 of the book) as a starting point.

Here is my solution displayed as an applet.

Class and Collaboration Diagrams

In addition to submitting your source for this assignment, please submit a class diagram of your program, and a collaboration diagram for one use case of your choice.

You do not need to use a fancy tool. NEAT, hand drawn diagrams are fine. You may bring your diagrams to class on the day the assigment is due. If you want to submit the diagrams electronically, they can be in postscript, pdf, gif, jpg, or MSWord.


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]