Assignment 2
COMP 86



Introduction

For the next few assignments, we will build up a traffic control system or similar type of interactive simulation or game, step by step. You can choose what to simulate and design the rules of the simulation, its graphic design, commands, and operations any way you like, as long as they follow the general requirements described in the assignments.

The simulation consists of a number of "vehicles" moving around on a "map" or background area. The vehicles could be cars and trucks, ships, Tufts shuttle buses, planetary explorer satellites, or anything you prefer. You can choose a project that is relevant/interesting to you, because you will be working on the same project for the next several assignments. You can choose any application that satisfies the technical requirements in each assignment (buttons, animation, picking, etc).

Your program display might look like a highway or railroad network with cars and trucks travelling along the roads or tracks, a ship radar display with other ships moving around the water, an air traffic control console, or a hypothetical system for keeping track of a set of satellites. It will have a display like a map or radar screen, showing the vehicles moving around and various pushbuttons and other controls to interact with the simulation and control the vehicles. Eventually, we will provide widgets for the user to interact with the map as a whole as well as to create, modify, and delete individual vehicles on it.

Assignment

For this assignment, write a Java/Swing application program that creates a window with some of the main elements you will need for this project. It should contain a drawing area and one or more control panel area with some buttons, scrollbars, or other widgets for the functions you might want in your final program. It should provide a reasonable layout for the window and its elements.

The first step, obviously, is to decide on what your application will be -- ships, planes, trains, space stations, asteroid explorers, or whatever you like.

Buttons and other Widgets

Each button should have an appropriate label. Give your widgets plausible-sounding names for features your simulation might have. As in Assignment 1, when the user presses a button, your program should print a different message for each of the buttons. Similarly, other widgets should print messages when they are used.

In addition, at least one widget should cause a change to something that is drawn in the drawing area. It does so by modifying some instance variable data that you maintain and that your paintComponent routine uses when it draws. Then you must call repaint() on the panel to cause your changes be displayed.

Drawing Area

This is the section of your window where the main action will eventually occur. For this assignment, create a drawing area widget, which will consume a significant part of your main window. (This object can be similar to the MyCanvas object used in lecture examples and it can subclass JPanel.) Inside this drawing area, draw some shapes, perhaps to represent your vehicles, landscape features, or grid markings.

Be sure to do all your drawing in your paintComponent() callback so that your drawing area can redraw itself when the system tells it to do so, usually because the window was exposed or resized. You can test this by resizing your window.

Main Program

Your main program, which is a public static method in your class called Main, should simply instantiate an object of class Main. Your constructor for Main will then set up your window, instantiate and initialize the objects you need, such as the buttons and drawing area, setVisible() the window, and then let the window system take over and wait for callbacks.

Once this program is running, it will simply display your objects, redrawing it as necessary if the window is resized or exposed, and responding to the buttons and other widgets.

The window should close and the application should quit when a user clicks on the close icon (the "X" or red dot in the top corner of the window title bar).

You should probably choose a BorderLayout for the main window, as in our Layout1 example. You can experiment with various ways of arranging the subcomponents to find one you think works best. Typically you would put the drawing area in the center, and the buttons and other items in some of the border areas.

(Note that if you use a FlowLayout instead, then to set the size of your drawing area you may need to use: setPreferredSize (new Dimension (width, height)) rather than: setSize (width, height).


Program Design and Practices

Your program design should exploit the features of object-oriented programming (encapsulation of code and data, support for abstract data types, polymorphism/overloading, inheritance).

You should follow these general Java programming practices:

And, finally, on your Java programs, for uniformity, please name your Java class that has your main program in it Main, in file Main.java


Design Documentation

In addition to your program, submit documentation about the design of your system in these forms:

Submit this documentation electronically in text form. Include it as part of the readme file that you submit with your assignment.

These diagrams may be trivial for this assignment, but will become more interesting with later assignments.


Grading Notes

Creating an excellent, nontrivial software application requires creativity beyond what your customers, or professor, can explicitly mandate. In general, great software satisfies a set of general requirements or requests, and then adds something beyond that. Grading for some of the assignments will reflect this fact as the semester progresses. Satisfying exactly the bare minimum for some assignments will merit a grade of approximately 80% or 90%, depending on the specific assignment (90% for this assignment). The remaining points will be awarded for additional work that adds something special, or features that are "nice to have" but not required. This is not necessarily easy to do. You will be both the software designer and the software developer in this course. If you do this, include a brief description in your readme file, as noted in the submission instructions.