Colors can be designated in Java by at least two ways;
- by using constants predefined in the color class.
- by constructing new colors using RGB values.
The colors shown below are defined in the color class.
Both the AWT color class and the IFC color class
define 13 colors using common names.
The IFC color class also defines 5 other shades of gray,
gray231, gray204, gray153, gray102, and gray51, and 2 shades
of almost-gray, gray160 and gray255.
To create custom colors, construct a new color using the
RGB values. Each has a range of 0 to 255.
Declare a new color
Color darkgreen;
and then call the constructor
darkgreen = new Color (0, 128, 0);
or do both simultaneously:
darkblue = new Color (0, 0, 128);
|