Rubberbanding


Draw rectangles setting the upper-left corner by pushing the mouse down and setting the width and height by dragging.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.rubberbanding.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Create a new applet named Rubberband.

  2. Define paint so that it draws a rectangle at x,y with width, height of w,h.

  3. Define mouseDown so that it sets the x,y of the rectangle to be drawn by paint.

  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 task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

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