Packages  This Package  Prev  Next  Index  

§1.9 Class Color

public  final  class  java.awt.Color
    extends  java.lang.Object  (I-§1.12)
{
        // Fields
    public final static Color black;	§1.9.1
    public final static Color blue;	§1.9.2
    public final static Color cyan;	§1.9.3
    public final static Color darkGray;	§1.9.4
    public final static Color gray;	§1.9.5
    public final static Color green;	§1.9.6
    public final static Color lightGray;	§1.9.7
    public final static Color magenta;	§1.9.8
    public final static Color orange;	§1.9.9
    public final static Color pink;	§1.9.10
    public final static Color red;	§1.9.11
    public final static Color white;	§1.9.12
    public final static Color yellow;	§1.9.13

        // Constructors
    public Color(float  r, float  g, float  b);	§1.9.14
    public Color(int  rgb);	§1.9.15
    public Color(int  r, int  g, int  b);	§1.9.16

        // Methods
    public Color brighter();	§1.9.17
    public Color darker();	§1.9.18
    public boolean equals(Object  obj);	§1.9.19
    public int getBlue();	§1.9.20
    public static Color getColor(String  nm);	§1.9.21
    public static Color getColor(String  nm, Color  v);	§1.9.22
    public static Color getColor(String  nm, int  v);	§1.9.23
    public int getGreen();	§1.9.24
    public static Color 	§1.9.25
        getHSBColor(float  h, float  s, float  b);
    public int getRed();	§1.9.26
    public int getRGB();	§1.9.27
    public int hashCode();	§1.9.28
    public static int HSBtoRGB(float  hue, float  saturation,	§1.9.29
                                             float  brightness);
    public static float[] RGBtoHSB(int  r, int  g, int  b,	§1.9.30
                                              float  hsbvals[]);
    public String toString();	§1.9.31
}
This class encapsulate colors using the RGB format. In this format, the red, blue, and green components of a color a each represented by an integer in the range 0-255. The value 0 indicates no contribution from this primary color. The value 255 indicates the maximum intensity of this color component.


Fields

black

public final static Color black = new Color(0, 0, 0)
The color black.

blue

public final static Color blue = new Color(0, 0, 255)
The color blue.

cyan

public final static Color cyan = new Color(0, 255, 255)
The color cyan.

darkGray

public final static Color darkGray = new Color(64, 64, 64)
The color dark gray.

gray

public final static Color gray = new Color(128, 128, 128)
The color gray.

green

public final static Color green = new Color(0, 255, 0);
The color green.

lightGray

public final static Color lightGray = new Color(192, 192, 192)
The color light gray.

magenta

public final static Color magenta = new Color(255, 0, 255)
The color magneta.

orange

public final static Color orange = new Color(255, 200, 0)
The color orange.

pink

public final static Color pink = new Color(255, 175, 175)
The color pink.

red

public final static Color red = new Color(255, 0, 0)
The color red.

white

public final static Color white = new Color(255, 255, 255)
The color white.

yellow

public final static Color yellow = new Color(255, 255, 0)
The color yellow.

Constructors

Color

public Color(float r, float g, float b)
Creates a color with the specified red, green, and blue values, where each of the values is in the range 0.0-1.0. The value 0.0 indicates no contribution from the primary color component. The value 1.0 indicates the maximum intensity of the primary color component.
The actual color used in rendering depends 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

Color

public Color(int rgb)
Creates a color with the the specified RGB value, where the red component is in bits 16-23 of the argument, the green component is in bits 8-15, of the argument, and the blue component is in bits 0-7. The value 0 indicates no contribution from the primary color component.
The actual color used in rendering depends on finding the best match given the color space available for a given output device.
Parameters:
rgb - an integer giving the red, green, and blue components
See Also:
getRGBdefault in class ColorModel (II-§2.1.9).

Color

public Color(int r, int g, int b)
Creates a color with the specified red, green, and blue components. The three arguments must each be in the range 0-255.
The actual color used in rendering depends 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

Methods

brighter

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

darker

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

equals

public boolean equals(Object obj)
The result is true if and only if the argument is not null and is a Color object that has the same red, green, and blue value as this object.
Parameters:
obj - the object to compare with
Returns:
true if the objects are the same; false otherwise.
Overrides:
equals in class Object (I-§1.12.3).

getBlue

public int getBlue()
Returns the blue component of this color. The result is in the range 0 to 255.
Returns:
the blue component of this color.

getColor

public static Color getColor(String nm)
Finds a color in the system properties.
The first argument is treated as the name of a system property to be obtained as if by the method System.getProperty (I-§1.18.10). The string value of this property is then interpreted as an integer value (see Integer.getInteger (I-§1.8.10) for information on how the string value is interpreted as an integer). This integer is then converted to a color by using the Color constructor that takes one integer argument (II-§1.9.15).


If the specified property is not found, or could not be parsed as an integer, then null is returned.
Parameters:
nm - the property name
Returns:
the color value of the property.

getColor

public static Color getColor(String nm, Color v)
Finds a color in the system properties.
The first argument is treated as the name of a system property to be obtained as if by the method System.getProperty (I-§1.18.10). The string value of this property is then interpreted as an integer value (see Integer.getInteger (I-§1.8.10) for information on how the string value is interpreted as an integer). This integer is then converted to a color by using the Color constructor that takes one integer argument (II-§1.9.15).


If the specified property is not found, or could not be parsed as an integer, then the color specified by the second argument is returned instead.
Parameters:
nm - the property name
v - default Color value
Returns:
the Color value of the property.

getColor

public static Color getColor(String nm, int v)
Finds a color in the system properties.
The first argument is treated as the name of a system property to be obtained as if by the method System.getProperty (I-§1.18.10). The string value of this property is then interpreted as an integer value (see Integer.getInteger (I-§1.8.10) for information on how the string value is interpreted as an integer).


If the specified property is not found, or could not be parsed as an integer, then the integer value v is used instead.
This integer is then converted to a color by using the Color constructor that takes one integer argument (II-§1.9.15).

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

getGreen

public int getGreen()
Returns the green component of this color. The result is in the range 0 to 255.
Returns:
the green component of this color.

getHSBColor

public static Color getHSBColor(float h, float s, float b)
Determines the hue, saturation, and brightness of a color. Each of the three components should each be a floating point number in the range .
Parameters:
h - the hue component
s - the saturation of the color
b - the brightness of the color
Returns:
the color object with the specified hue, saturation, and brightness.

getRed

public int getRed()
Returns the red component of this color. The result is in the range 0 to 255.
Returns:
the red component of this color

getRGB

public int getRGB()
Calculates a single integer representing the red, green, and blue components of this color. The red, green, and blue components of the color are each scaled to be a value between 0 (absence of the color) and 255 (complete saturation). The integer returned is the number between 0 and 0xFFFFFF such that bits 16-23 are the red value, bits 8-15 are the green value, and bits 0-7 are the blue value.
Returns:
an integer representing this color.
See Also:
getRGBdefault in class ColorModel (II-§2.1.9).

hashCode

public int hashCode()
Returns:
a hash code value for this object.
Overrides:
hashCode in class Object (I-§1.12.6).

HSBtoRGB

public static int
HSBtoRGB(float hue, float saturation, float brightness)
Converts a color specified by hue, saturation, and brightness, to a corresponding RGB value.
Parameters:
hue - the hue component of the color
saturation - the saturation of the color
brightness - the brightness of the color
Returns:
the RGB value (II-§1.9.27) of the color with the indicated hue, saturation, and brightness.

RGBtoHSB

public static float[]
RGBtoHSB(int r, int g, int b, float hsbvals[])
Converts a color specified by its red, green, and blue components to hue, saturation, and brightness.
If the hsbvals argument is null, then a new array is allocated to return the result. Otherwise, hsbvals is returned as the result, with the values put into that array.
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:
an array of three elements containing the hugh, saturation, and brightness (in that order), of the color with the indicated red, geen, and blue components.
See Also:
getRGBdefault in class ColorModel (II-§2.1.9)
getRGB (II-§1.9.27).

toString

public String toString()
Returns:
a string representation of this color.
Overrides:
toString in class Object (I-§1.12.9).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com