CSCI A348
Mastering the World-Wide Web

Spring `96 Assignment #4
Java Lab #2: 11-12 April 1996

Attendance and participation in this lab, along with the other Java labs, form the grade for this assignment. Students not able to attend a lab may demonstrate mastery of the lab exercises to the lab AI outside of class for the grade credit. Students with more Java/programming experience should pair with less experienced students to work together at a workstation in the labs. The less experienced student should drive the console with the more experienced student tutoring and advising to complete as much of the following exercises as they can during the lab period. Collaboration and questions are encouraged.

Goal 1: Complete any unfinished goals from the previous lab
Goal 2: Write a simple sketchpad applet
Write a small applet to draw a line wherever the mouse moves while the mouse button is down. This can be done by defining only the mouseDown(), mouseDrag() and mouseUp() methods. mouseDown() should only save its argument coordinates into instance variables of the applet. mouseDrag() should only draw a line on the display from the saved coordinates to its argument coordinates, then save its argument coordinates in the instance variables. mouseUp() need only draw the line. Note that getGraphics() will return the Graphics object (ie, the drawing surface) of the applet. See the API User's Guide about the Graphics object and what method of its to use to draw a line within it.
Goal 3: Enhance your sketchpad applet
  1. Look up the handleEvent() method of the AWT Component object in the API User's Guide. How does it compare to all the mouse*() methods you've written? Might there be an advantage to using it instead?
  2. With a sketch displayed, try iconifying your browser and covering it partially with another window. What happens to the sketch? Use the double-buffering technique (as demonstrated in the StackedRects Java development example) to overcome this problem.
  3. Implement a way to clear your sketchpad by typing a certain key. How could you do this with a double-click on the mouse instead?
  4. Black on grey is boring. Modify your applet to accept parameters for the line color and the background color. Learn about the Color object to do this.
<kinzler@cs.indiana.edu> 10 April 1996