|CIT 591 ArrayDisplay 2.0
Fall 2003, David Matuszek
This is a revised version of the
ArrayDisplay class, with added
For Assignment 5 (Traffic Jam), you can print
your results on
System.out if you prefer. However, here is a simple
class that, if added to your program, will make your output simpler and more
To create an object of type
ArrayDisplay, you must first define
a two-dimensional array of Objects (of any sort). For example, you might have
a two-dimensional array of
Vehicles. Use this array as a parameter
ArrayDisplay constructor. For example:
Vehicle vehicles = new Vehicle; // ... put some vehicles into the array ... ArrayDisplay view = new ArrayDisplay(vehicles);
It is better to put something into the array before using it to create an
null values in the array will be ignored (not displayed) by
ArrayDisplay class; other values will be displayed by calling
you don't supply this method, the
toString() method inherited from
Object will be used, with unpleasant results.) Do not create
more than one
ArrayDisplay for your array.
New in version 2.0:
There is now a second
The purpose of this second array is to give you a way to display destinations.
When you make a change in your array, it is not automatically displayed;
you have to call the
repaint() method of your
object to make the changes appear on the screen. For example:
// ... make some changes to the vehicles array ... view.repaint();
To make sure that your changes don't fly by too fast for the eye to follow,
there is a built-in one second (1000 millisecond) delay between each change
to the display.
ArrayDisplay has two additional (trivial) features. You can tell
ArrayDisplay object to display a message with
view.displayMessage("Going OK so far.");
The message field is initially pretty short. If you want a longer field, just resize the window.
ArrayDisplay has a
Quit button that
will end your program. (The close box in the upper-right corner has not been
ArrayDisplay, just copy the source code from here
and drop it into the same folder as the rest of your program.
Also note: (1)
ArrayDisplay has a main program, used for testing
purposes, which you may ignore, and (2) you are welcome to modify
in any way you like.