Java Reference
In-Depth Information
TABLE 12-5 Some Constructors and Methods of the class Color (continued)
Color( float r, float g, float b)
//Constructor
//Creates a Color object with the red value r, green value g,
//and blue value b. In this case, r, g, and b can be between 0
//and 1.0.
//Example: new
Color(1.0, 0, 0)
//
creates a color with no green or blue component.
public Color brighter()
//Returns a Color that is brighter.
public Color darker()
//Returns a Color that is darker.
public boolean equals(Object o)
//Returns true if the color of this object is the same as the
//color of the object o; false otherwise.
public int getBlue()
//Returns the value of the blue component.
public int getGreen()
//Returns the value of the green component.
public int getRed()
//Returns the value of the red component.
public int getRGB()
//Returns the RGB value.
public String toString()
//Returns a string with the information about the color.
You can use the methods setBackground and setForeground , described in Table
12-1, to set the background and foreground color of a component.
Java uses the color scheme known as RGB, where R stands for red, G for green, and
B for blue, respectively. You create instances of Color by mixing red, green, and
blue hues in various proportions. The class Color contains three constructors, as
shown in Table 12-5. In the first constructor, an RGB value is represented as three
int values. The second constructor specifies an RGB value as a single integer. In
either form, the closer an r, g, or b value is to 255, the more hue is mixed into the
color. For example, if you use the first constructor, pure red is produced by mixing
red 255, green 0, and blue 0 parts each. To produce the color red, you use the first
constructor as follows:
1
2
Color redColor = new Color(255, 0, 0);
Various tones of black, white, and gray can be created by mixing all three colors in the
same proportion. For example, the color white has the RGB values 255, 255, 255, and
Search WWH ::




Custom Search