Spring `96 Assignment #4
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.
Java Lab #2: 11-12 April 1996
10 April 1996
- 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 save its argument coordinates into instance variables of the
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
object (ie, the drawing surface) of the applet. See the
API User's Guide
Graphics object and what method of its to
use to draw a line within it.
- Goal 3: Enhance your sketchpad applet
- Look up the
of the AWT
Component object in the
API User's Guide.
How does it compare to all the
you've written? Might there be an advantage to using it
- 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.
- 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?
- 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.