Java Graphics  «Prev 

AWT Colors in Java

Colors in Java adhere to a standard color system known as RGB (Red Green Blue). Under the RGB color system, each Java color consists of a red, green, and blue component. Each of these components can have a value between 0 and 255. As an example, the pure color blue has an RGB value of (0, 0, 255).
The AWT includes a Color class that is used to specify Java colors. The Color class encapsulates the three RGB color components and provides methods for accessing each one individually. To create a Color object, you pass the three RGB components to the Color constructor:

Color blue = new Color(0, 0, 255);

You could also use one of the constant Color objects that represent some of the more commonly used colors such as
Color.blue, Color.red, Color.black.

The Color class is used with many of the AWT graphics operations.
For example, the setBackgroundColor() method of the Graphics object accepts a Color object as its only parameter.