|
Colors are defined by the class java.awt.Color RGB, with an alpha transparency factor, is the default colorspace. Specify a color, for example, in one of the constructors with either int 0-255, or float 0.0-1.0: Color red = new Color(
0xFF,0,0); // R,G,B For convenience, several colors are available as Class constants, e.g. Color.blue,Color.white, etc. To set the current drawing color in the graphics context:
g.setColor(Color
c);//g =
Graphics object
The
background and foreground colors of components, e.g. a panel, can be set
with setBackground(Color
c); Similarly,
"getter" methods are paired with these methods to obtain the
colors: Color c = g.getColor();//g = Graphics object //
In an applet or other Component object:
|
||||||||||||
|
|||||||||||||