13. Painting
Some objects have default appearance. When they are created, OS decorates with a pre-defined appearance.
Some components don't have any intrinsic appearance. These are Applet, Panel, Frame and Canvas. For these objects paint() method is used to render them.
public void paint(Graphics g)
The paint() method provides a graphics context (an instance of Graphics class) for drawing. This is passed as a method argument.
A Graphics object encapsulates state information needed for the basic rendering operations that Java supports. This state information includes the following properties:
- The Component object on which to draw.
- A translation origin for rendering and clipping coordinates.
- The current clip.
- The current color.
- The current font.
- The current logical pixel operation function (XOR or Paint).
- The current XOR alternation color.
We can use this Graphics object to achieve the following functionality:
1. Selecting a color - g.setColor(Color)
There are 13 predefined colors in Color class. Or create a new color using Color(R,G,B)