Chapter 14, “The java.awt Package: Painting”

The Canvas class of java.awt provides a general GUI component for drawing images and text. It does not support drawing methods of its own, but provides access to a Graphics object via its paint() method.

The paint() method is invoked upon the creation and update of a Canvas object. It enables the Graphics object that is associated with the Canvas object to be updated. The paint() method should not be directly invoked, but it can be indirectly accessed using the repaint() method. The AWT creates a background thread that automatically causes the paint() methods of Canvas, Frame, Panel, Applet, and other GUI components as required to update areas that need repainting. You can implement custom drawing and painting operations in your applet or application by extending the Canvas class and overriding its paint() method.

The Graphics class is where all the low-level drawing methods are implemented. These methods can be used directly to draw objects and text or can be combined to display more elaborate screen objects. The Graphics drawing methods enable you to draw and fill a number of geometrical shapes, including lines, arcs, ovals, rectangles, rounded rectangles, and polygons.

The AWT supports a painting feature known as clipping. Clipping enables you to restrict painting (or drawing) operations to a particular shape or region instead of the whole window.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.96.247