Zooming In on a Selection (Visual J++)

Take the following steps to add code that lets you select an area with a mouse, and zoom in on the selected area.

1. Start with the project that you created in Loading and Displaying an Image.

2. In the LEAD1 control's MouseDown procedure, add the following code. In online help, you can use the Edit pull-down menu to copy the block of code.

private void LEAD1_mouseDown(Object source, MouseEvent e)
{
   // Enable AutoRubberBand
   LEAD1.setAutoRubberBand( true );
   LEAD1.setMousePointer( (short) 2 );
}

3. In the LEAD1 control's Rubberband event, add the following code.

private void LEAD1_rubberBand(Object source, Event e)
{
   LEAD1.setMousePointer( (short) 0 );

   // Zoom in on the selection.
   int nZoomleft = (int) LEAD1.getRubberBandLeft();
   int nZoomtop = (int) LEAD1.getRubberBandTop();
   int nZoomwidth = (int) LEAD1.getRubberBandWidth();
   int nZoomheight = (int) LEAD1.getRubberBandHeight();

   // Zoom in on the rectangle defined by the rubberband
   LEAD1.ZoomToRect( nZoomleft, nZoomtop, nZoomwidth, nZoomheight );
   LEAD1.ForceRepaint();
}

4. Run your program to test it.