Clipping

The AWT supports a painting feature known as clipping. Clipping enables you to restrict painting (or drawing) operations to a particular shape. The Shape interface is implemented by classes that define geometric shapes, such as Rectangle and Polygon. The setClip() method of the Graphics class specifies a clipping region and takes a Shape object as an argument. (Another version of the setClip() method takes x, y, width, and height arguments.) When a clipping region is specified, painting of a Graphics object is limited to the clipping region. The ClipApp program of Listing 14.4 shows how clipping works. This program creates a Rectangle object that is set as the clipping area. It is located at (100,100) and is 200 pixels wide and high. ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.