CPSC 170 Post Lab 3: Drawing Lines

Due Tuesday, Feb 12

Problem (derived from Lewis and Loftus 6.15)

Write an applet that draws a polyline shape using mouse clicks, where each click adds a new line segment from the last point. Specifically, your applet should behave as follows: Try my demo to be sure you understand these behaviors.

Program Design

Your program must do the following: Notice that this means that you will need to keep track of the number of points in the line separately instead of passing the length of the arrays to the drawPolyline method.

I strongly advise that you proceed as follows:

  1. Write an applet that draws a polyline from the clicks entered by the user. Don't deal with the number of points exceeding 10 or removing the last segment. Recall that to listen for mouse events you will have to do the following: To refresh your memory on how an applet that handles mouse clicks works, look at Dots.java from lab 11 in CPSC 120 -- it contains all of the elements above.

  2. Now make the arrays double in size when the user exceeds the capacity of the current arrays. Since you know the size of the arrays and the number of points, this is easy to check for when the user clicks. Just write a method increaseSize that increases the capacity of the arrays that define the polyline. This is very much like what the CDCollection class does.

  3. Finally add the feature where clicking near the last point removes the last line. To do this you will need to do the following:

As always, document each of your methods and any large or unclear sections of code, and include documentation at the top that gives an overview of the applet.

What to turn in

Turn in hardcopy and e-mail a tar file of your postlab directory to bloss@cs.roanoke.edu. IMPORTANT: Put "Postlab 3" (no quotes) in the subject.