Java Reference
In-Depth Information
class ClipDemoCanvas extends Canvas {
public void paint (Graphics g) {
g.setGrayScale (255);
g.fillRect (0, 0, getWidth(), getHeight());
int m = Math.min (getWidth(), getHeight());
g.setGrayScale (0);
g.setStrokeStyle (Graphics.DOTTED);
g.drawLine (0, 0, m, m);
g.setClip (m / 4, m / 4, m / 2, m / 2);
g.setStrokeStyle (Graphics.SOLID);
g.drawLine (0, 0, m, m);
}
}
Figure 3.11 shows the resulting image. Although both lines have identical start and end points, only the
part covered by the clipping area is replaced by a solid line.
Figure 3.11. Output of the clipRect() example: Only the part covered by the clipping
area is redrawn solid, although the line coordinates are identical.
When the paint() method is called from the system, a clip area may already be set. This may be the
case if the application just requested repainting of a limited area using the parameterized repaint call, or
if the device just invalidated a limited area of the display, for example if a pop-up dialog indicating an
incoming call was displayed but did not cover the whole display area.
Actually, clipRect() does not set a new clipping area, but instead shrinks the current clip area to
the intersection with the given rectangle. In order to enlarge the clip area, use the setClip() method.
The current clip area can be queried using the getClipX() , getClipY() , getClipWidth() ,
and getClipHeight() methods. When drawing is computationally expensive, this information can
be taken into account in order to redraw only the areas of the screen that need an update.
Text and Fonts
 
 
 
Search WWH ::




Custom Search