Rendering Methods


When you set an attribute, you pass in the appropriate attribute object. For example, to change the paint attribute to a blue-green gradient fill, you would construct a GradientPaint object and then call setPaint.

gp = new GradientPaint(0f,0f,blue,0f,30f,green);

Graphics2D holds references to its attribute objects--they are not cloned. If you alter an attribute object that is part of the Graphics2D context, you need to call the appropriate set method to notify the context. Modifying an attribute object during rendering causes unpredictable behavior.

Graphics2D Rendering Methods

Graphics2D provides the following general rendering methods that can be used to draw any geometry primitive, text, or image:

In addition, Graphics2D supports the Graphics rendering methods for particular shapes, such as drawOval and fillRect.