java.awt
Class Color

java.lang.Object
  |
  +--java.awt.Color

public final class Color
extends Object

A class to encapsulate RGB Colors.


Field Summary
static Color black
          The color black.
static Color blue
          The color blue.
static Color cyan
          The color cyan.
static Color darkGray
          The color dark gray.
static Color gray
          The color gray.
static Color green
          The color green.
static Color lightGray
          The color light gray.
static Color magenta
          The color magneta.
static Color orange
          The color orange.
static Color pink
          The color pink.
static Color red
          The color red.
static Color white
          The color white.
static Color yellow
          The color yellow.
 
Constructor Summary
Color(float r, float g, float b)
          Creates a color with the specified red, green, and blue values in the range (0.0 - 1.0).
Color(int rgb)
          Creates a color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color(int r, int g, int b)
          Creates a color with the specified red, green, and blue values in the range (0 - 255).
 
Method Summary
 Color brighter()
          Returns a brighter version of this color.
 Color darker()
          Returns a darker version of this color.
 boolean equals(Object obj)
          Compares this object against the specified object.
 int getBlue()
          Gets the blue component.
static Color getColor(String nm)
          Gets the specified Color property.
static Color getColor(String nm, Color v)
          Gets the specified Color property of the specified Color.
static Color getColor(String nm, int v)
          Gets the specified Color property of the color value.
 int getGreen()
          Gets the green component.
static Color getHSBColor(float h, float s, float b)
          A static Color factory for generating a Color object from HSB values.
 int getRed()
          Gets the red component.
 int getRGB()
          Gets the RGB value representing the color in the default RGB ColorModel.
 int hashCode()
          Computes the hash code.
static int HSBtoRGB(float hue, float saturation, float brightness)
          Returns the RGB value defined by the default RGB ColorModel, of the color corresponding to the given HSB color components.
static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
          Returns the HSB values corresponding to the color defined by the red, green, and blue components.
 String toString()
          Returns the String representation of this Color's values.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

white

public static final Color white
The color white.


lightGray

public static final Color lightGray
The color light gray.


gray

public static final Color gray
The color gray.


darkGray

public static final Color darkGray
The color dark gray.


black

public static final Color black
The color black.


red

public static final Color red
The color red.


pink

public static final Color pink
The color pink.


orange

public static final Color orange
The color orange.


yellow

public static final Color yellow
The color yellow.


green

public static final Color green
The color green.


magenta

public static final Color magenta
The color magneta.


cyan

public static final Color cyan
The color cyan.


blue

public static final Color blue
The color blue.

Constructor Detail

Color

public Color(int r,
             int g,
             int b)
Creates a color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering will depend on finding the best match given the color space available for a given output device.

Parameters:
r - the red component
g - the green component
b - the blue component
See Also:
getRed(), getGreen(), getBlue(), getRGB()

Color

public Color(int rgb)
Creates a color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering will depend on finding the best match given the color space available for a given output device.

Parameters:
rgb - the combined RGB components
See Also:
ColorModel.getRGBdefault(), getRed(), getGreen(), getBlue(), getRGB()

Color

public Color(float r,
             float g,
             float b)
Creates a color with the specified red, green, and blue values in the range (0.0 - 1.0). The actual color used in rendering will depend on finding the best match given the color space available for a given output device.

Parameters:
r - the red component
g - the red component
b - the red component
See Also:
getRed(), getGreen(), getBlue(), getRGB()
Method Detail

getRed

public int getRed()
Gets the red component.

See Also:
getRGB()

getGreen

public int getGreen()
Gets the green component.

See Also:
getRGB()

getBlue

public int getBlue()
Gets the blue component.

See Also:
getRGB()

getRGB

public int getRGB()
Gets the RGB value representing the color in the default RGB ColorModel. (Bits 24-31 are 0xff, 16-23 are red, 8-15 are green, 0-7 are blue).

See Also:
ColorModel.getRGBdefault(), getRed(), getGreen(), getBlue()

brighter

public Color brighter()
Returns a brighter version of this color.


darker

public Color darker()
Returns a darker version of this color.


hashCode

public int hashCode()
Computes the hash code.

Overrides:
hashCode in class Object
See Also:
Hashtable

equals

public boolean equals(Object obj)
Compares this object against the specified object.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.
See Also:
Hashtable

toString

public String toString()
Returns the String representation of this Color's values.

Overrides:
toString in class Object

getColor

public static Color getColor(String nm)
Gets the specified Color property.

Parameters:
nm - the name of the color property

getColor

public static Color getColor(String nm,
                             Color v)
Gets the specified Color property of the specified Color.

Parameters:
nm - the name of the color property
v - the specified color
Returns:
the new color.

getColor

public static Color getColor(String nm,
                             int v)
Gets the specified Color property of the color value.

Parameters:
nm - the name of the color property
v - the color value
Returns:
the new color.

HSBtoRGB

public static int HSBtoRGB(float hue,
                           float saturation,
                           float brightness)
Returns the RGB value defined by the default RGB ColorModel, of the color corresponding to the given HSB color components.

Parameters:
hue - the hue component of the color
saturation - the saturation of the color
brightness - the brightness of the color
See Also:
ColorModel.getRGBdefault(), getRGB()

RGBtoHSB

public static float[] RGBtoHSB(int r,
                               int g,
                               int b,
                               float[] hsbvals)
Returns the HSB values corresponding to the color defined by the red, green, and blue components.

Parameters:
r - the red component of the color
g - the green component of the color
b - the blue component of the color
hsbvals - the array to be used to return the 3 HSB values, or null
Returns:
the array used to store the results [hue, saturation, brightness]
See Also:
ColorModel.getRGBdefault(), getRGB()

getHSBColor

public static Color getHSBColor(float h,
                                float s,
                                float b)
A static Color factory for generating a Color object from HSB values.

Parameters:
h - the hue component
s - the saturation of the color
b - the brightness of the color
Returns:
the Color object for the corresponding RGB color