Help: Rubberbanding


Help is available for each task, or you can go straight to the solution source code.

Task 1

Create a new applet named Rubberband.

Task 2

Define paint so that it draws a rectangle at x,y with width, height of w,h.
See Graphics for drawing methods.

Task 3

Define mouseDown so that it sets the x,y of the rectangle to be drawn by paint.
The x and y instance variables have been defined for you. Copy the values of the arguments of mouseDown into the instance variables.

Return true from this method as you have handled the event.

Task 4

Define mouseDrag so that it sets the w,h of the rectangle. Do not allow users to drag to the left or above the initial mouse down point. Schedule a repaint so that the new rectangle is drawn. Consider why the old rectangles do not appear (in other words, why is there no shadow?).
The width is the new mouse location minus the mouse down x location. To prevent illegal drawing, set the width or height to 0 if they are found to be negative.

Return true from this method as you have handled the event.


Copyright © 1996-1997 MageLang Institute. All Rights Reserved.