Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: Color [javadoc | source]
java.lang.Object
   java.awt.Color

All Implemented Interfaces:
    Paint, java$io$Serializable

Direct Known Subclasses:
    DerivedColor, ColorUIResource, UIResource, SystemColor

The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace . Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a float value in the range 0.0 - 1.0 or 0 - 255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never premultiplied by the alpha component.

The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .

Field Summary
public static final  Color white    The color white. In the default sRGB space. 
public static final  Color WHITE    The color white. In the default sRGB space.
    since: 1.4 -
 
public static final  Color lightGray    The color light gray. In the default sRGB space. 
public static final  Color LIGHT_GRAY    The color light gray. In the default sRGB space.
    since: 1.4 -
 
public static final  Color gray    The color gray. In the default sRGB space. 
public static final  Color GRAY    The color gray. In the default sRGB space.
    since: 1.4 -
 
public static final  Color darkGray    The color dark gray. In the default sRGB space. 
public static final  Color DARK_GRAY    The color dark gray. In the default sRGB space.
    since: 1.4 -
 
public static final  Color black    The color black. In the default sRGB space. 
public static final  Color BLACK    The color black. In the default sRGB space.
    since: 1.4 -
 
public static final  Color red    The color red. In the default sRGB space. 
public static final  Color RED    The color red. In the default sRGB space.
    since: 1.4 -
 
public static final  Color pink    The color pink. In the default sRGB space. 
public static final  Color PINK    The color pink. In the default sRGB space.
    since: 1.4 -
 
public static final  Color orange    The color orange. In the default sRGB space. 
public static final  Color ORANGE    The color orange. In the default sRGB space.
    since: 1.4 -
 
public static final  Color yellow    The color yellow. In the default sRGB space. 
public static final  Color YELLOW    The color yellow. In the default sRGB space.
    since: 1.4 -
 
public static final  Color green    The color green. In the default sRGB space. 
public static final  Color GREEN    The color green. In the default sRGB space.
    since: 1.4 -
 
public static final  Color magenta    The color magenta. In the default sRGB space. 
public static final  Color MAGENTA    The color magenta. In the default sRGB space.
    since: 1.4 -
 
public static final  Color cyan    The color cyan. In the default sRGB space. 
public static final  Color CYAN    The color cyan. In the default sRGB space.
    since: 1.4 -
 
public static final  Color blue    The color blue. In the default sRGB space. 
public static final  Color BLUE    The color blue. In the default sRGB space.
    since: 1.4 -
 
 int value    The color value. 
Constructor:
 public Color(int rgb) 
 public Color(int rgba,
    boolean hasalpha) 
 public Color(int r,
    int g,
    int b) 
 public Color(float r,
    float g,
    float b) 
 public Color(ColorSpace cspace,
    float[] components,
    float alpha) 
    Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha. The number of components is determined by the type of the ColorSpace. For example, RGB requires 3 components, but CMYK requires 4 components.
    Parameters:
    cspace - the ColorSpace to be used to interpret the components
    components - an arbitrary number of color components that is compatible with the ColorSpace
    alpha - alpha value
    Throws:
    IllegalArgumentException - if any of the values in the components array or alpha is outside of the range 0.0 to 1.0
    Also see:
    getComponents
    getColorComponents
 public Color(int r,
    int g,
    int b,
    int a) 
 public Color(float r,
    float g,
    float b,
    float a) 
Method from java.awt.Color Summary:
HSBtoRGB,   RGBtoHSB,   brighter,   createContext,   darker,   decode,   equals,   getAlpha,   getBlue,   getColor,   getColor,   getColor,   getColorComponents,   getColorComponents,   getColorSpace,   getComponents,   getComponents,   getGreen,   getHSBColor,   getRGB,   getRGBColorComponents,   getRGBComponents,   getRed,   getTransparency,   hashCode,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.Color Detail:
 public static int HSBtoRGB(float hue,
    float saturation,
    float brightness) 
    Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.

    The saturation and brightness components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

    The integer that is returned by HSBtoRGB encodes the value of a color in bits 0-23 of an integer value that is the same format used by the method getRGB . This integer can be supplied as an argument to the Color constructor that takes a single integer argument.

 public static float[] RGBtoHSB(int r,
    int g,
    int b,
    float[] hsbvals) 
    Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.

    If the hsbvals argument is null, then a new array is allocated to return the result. Otherwise, the method returns the array hsbvals, with the values put into that array.

 public Color brighter() 
    Creates a new Color that is a brighter version of this Color.

    This method applies an arbitrary scale factor to each of the three RGB components of this Color to create a brighter version of this Color. The {@code alpha} value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

 public synchronized PaintContext createContext(ColorModel cm,
    Rectangle r,
    Rectangle2D r2d,
    AffineTransform xform,
    RenderingHints hints) 
    Creates and returns a PaintContext used to generate a solid color field pattern. See the specification of the method in the Paint interface for information on null parameter handling.
 public Color darker() 
    Creates a new Color that is a darker version of this Color.

    This method applies an arbitrary scale factor to each of the three RGB components of this Color to create a darker version of this Color. The {@code alpha} value is preserved. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.

 public static Color decode(String nm) throws NumberFormatException 
    Converts a String to an integer and returns the specified opaque Color. This method handles string formats that are used to represent octal and hexadecimal numbers.
 public boolean equals(Object obj) 
    Determines whether another object is equal to this Color.

    The result is true if and only if the argument is not null and is a Color object that has the same red, green, blue, and alpha values as this object.

 public int getAlpha() 
    Returns the alpha component in the range 0-255.
 public int getBlue() 
    Returns the blue component in the range 0-255 in the default sRGB space.
 public static Color getColor(String nm) 
    Finds a color in the system properties.

    The argument is treated as the name of a system property to be obtained. The string value of this property is then interpreted as an integer which is then converted to a Color object.

    If the specified property is not found or could not be parsed as an integer then null is returned.

 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. The string value of this property is then interpreted as an integer which is then converted to a Color object.

    If the specified property is not found or cannot be parsed as an integer then the Color specified by the second argument is returned instead.

 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. The string value of this property is then interpreted as an integer which is then converted to a Color object.

    If the specified property is not found or could not be parsed as an integer then the integer value v is used instead, and is converted to a Color object.

 public float[] getColorComponents(float[] compArray) 
    Returns a float array containing only the color components of the Color, in the ColorSpace of the Color. If compArray is null, an array with length equal to the number of components in the associated ColorSpace is created for the return value. Otherwise, compArray must have at least this length and it is filled in with the components and returned.
 public float[] getColorComponents(ColorSpace cspace,
    float[] compArray) 
    Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter. If compArray is null, an array with length equal to the number of components in cspace is created for the return value. Otherwise, compArray must have at least this length, and it is filled in with the components and returned.
 public ColorSpace getColorSpace() 
    Returns the ColorSpace of this Color.
 public float[] getComponents(float[] compArray) 
    Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color. If compArray is null, an array with length equal to the number of components in the associated ColorSpace plus one is created for the return value. Otherwise, compArray must have at least this length and it is filled in with the components and returned.
 public float[] getComponents(ColorSpace cspace,
    float[] compArray) 
    Returns a float array containing the color and alpha components of the Color, in the ColorSpace specified by the cspace parameter. If compArray is null, an array with length equal to the number of components in cspace plus one is created for the return value. Otherwise, compArray must have at least this length, and it is filled in with the components and returned.
 public int getGreen() 
    Returns the green component in the range 0-255 in the default sRGB space.
 public static Color getHSBColor(float h,
    float s,
    float b) 
    Creates a Color object based on the specified values for the HSB color model.

    The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0). The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.

 public int getRGB() 
    Returns the RGB value representing the color in the default sRGB ColorModel . (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).
 public float[] getRGBColorComponents(float[] compArray) 
    Returns a float array containing only the color components of the Color, in the default sRGB color space. If compArray is null, an array of length 3 is created for the return value. Otherwise, compArray must have length 3 or greater, and it is filled in with the components and returned.
 public float[] getRGBComponents(float[] compArray) 
    Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space. If compArray is null, an array of length 4 is created for the return value. Otherwise, compArray must have length 4 or greater, and it is filled in with the components and returned.
 public int getRed() 
    Returns the red component in the range 0-255 in the default sRGB space.
 public int getTransparency() 
    Returns the transparency mode for this Color. This is required to implement the Paint interface.
 public int hashCode() 
    Computes the hash code for this Color.
 public String toString() 
    Returns a string representation of this Color. This method is intended to be used only for debugging purposes. The content and format of the returned string might vary between implementations. The returned string might be empty but cannot be null.