CS 112b
Spring 1999
Ileana Streinu

Midterm Exam
Part 2

Tuesday, March 2, 1999 1:00 - 2:50pm

Getting organized

Some advice on how to proceed


Problem 1 (50 points)

The applet has two buttons and responds to mouse clicks. The buttons are labeled Rectangle and Segment.

If the last button pressed on was Rectangle, the user can draw a rectangle by click-and-drag. When the user presses the Segment button, a diagonal of the rectangle (from the top leftmost corner to the bottom righmost corner) is drawn. Then the applet will not respond to mouse clicks for drawing rectangles until the Rectangle button is pressed again. In the beginning, the applet behaves as if the Rectangle button has been pressed.

The applet draws only one rectangle at a time. It does not remember what the user did in the past. Each time the user draws a new rectangle, the one that was there before will disappear. Each time the rectangle button is pressed, the old one disappears from the screen.

Work under the simplifying assumption that the rectangle is always created from the upper leftmost corner towards the bottom rightmost corner (otherwise the code is slightly more complex).

The rectangle drawing is done by click and drag. The user clicks on a point on the screen, then drags the mouse towards the bottom right part of the screen and finally releases the mouse. A rectangle is drawn at all these events. The upper left corner is the point where the user first clicked and the lower right corner is where the mouse is currently being positioned.

The diagonal drawn when the Segment button is pressed goes from the upper left corner to the bottom right corner of the current rectangle. Both the rectangle and the diagonal should be drawn, in this case.

Extra features to be added


Problem 2 (50 points)

For this applet, the user clicks and drags with the mouse to draw rectangles, as before. However, at any time all the rectangles are redrawn, not just the last one.

Extra feature

(if you finished already, add this extra feature for a bit of extra credit)

The rectangles are drawn with alternating colors: the first one is black, the second is red, then a next one is black again, then a red one follows, etc.
Last modified March 1, 1999.

Ileana Streinu