Class java.awt.Color
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.awt.Color

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

public class Color
extends Object
implements Serializable
This class encapsulates colors using the RGB format. In RGB format, the red, blue, and green components of a color are 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.

Although the Color class is based on the three-component RGB model, the class provides a set of convenience methods for converting between RGB and HSB colors. For a definition of the RGB and HSB color models, see Foley, van Dam, Feiner, and Hughes, Computer Graphics: Principles and Practice.

Version:
1.34, 07/01/98
Author:
Sami Shaio, Arthur van Hoff
Since:
JDK1.0

Variable Index

 o black
The color black.
 o blue
The color blue.
 o cyan
The color cyan.
 o darkGray
The color dark gray.
 o gray
The color gray.
 o green
The color green.
 o lightGray
The color light gray.
 o magenta
The color magenta.
 o orange
The color orange.
 o pink
The color pink.
 o red
The color red.
 o white
The color white.
 o yellow
The color yellow.

Constructor Index

 o java.awt.Color(int, int, int)
Creates a color with the specified red, green, and blue components.
 o java.awt.Color(int)
Creates a color with 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.
 o java.awt.Color(float, float, float)
Creates a color with the specified red, green, and blue values, where each of the values is in the range 0.0-1.0.

Method Index

 o HSBtoRGB(float, float, float)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the RGB model.
 o RGBtoHSB(int, int, int, float[])
Converts the components of a color, as specified by the RGB model, to an equivalent set of values for hue, saturation, and brightness, the three components of the HSB model.
 o brighter()
Creates a brighter version of this color.
 o darker()
Creates a darker version of this color.
 o decode(String)
Converts a string to an integer and returns the specified color.
 o equals(Object)
Determines whether another object is equal to this color.
 o getBlue()
Gets the blue component of this color.
 o getColor(String)
Finds a color in the system properties.
 o getColor(String, Color)
Finds a color in the system properties.
 o getColor(String, int)
Finds a color in the system properties.
 o getGreen()
Gets the green component of this color.
 o getHSBColor(float, float, float)
Creates a Color object based on values supplied for the HSB color model.
 o getRGB()
Gets the RGB value representing the color in the default RGB ColorModel.
 o getRed()
Gets the red component of this color.
 o hashCode()
Computes the hash code for this color.
 o toString()
Creates a string that represents this color and indicates the values of its RGB components.

Variables

 o black
public static final java.awt.Color black
The color black.

 o blue
public static final java.awt.Color blue
The color blue.

 o cyan
public static final java.awt.Color cyan
The color cyan.

 o darkGray
public static final java.awt.Color darkGray
The color dark gray.

 o gray
public static final java.awt.Color gray
The color gray.

 o green
public static final java.awt.Color green
The color green.

 o lightGray
public static final java.awt.Color lightGray
The color light gray.

 o magenta
public static final java.awt.Color magenta
The color magenta.

 o orange
public static final java.awt.Color orange
The color orange.

 o pink
public static final java.awt.Color pink
The color pink.

 o red
public static final java.awt.Color red
The color red.

 o white
public static final java.awt.Color white
The color white.

 o yellow
public static final java.awt.Color yellow
The color yellow.

Constructors

 o 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.
Since:
JDK1.0
See Also:
getRed., getGreen., getBlue., getRGB.
 o Color
public Color(int rgb)
Creates a color with 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 zero 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.
Since:
JDK1.0
See Also:
getRGBdefault, getRed., getGreen., getBlue., getRGB.
 o 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
Since:
JDK1.0
See Also:
getRed., getGreen., getBlue., getRGB.

Methods

 o HSBtoRGB
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 RGB model.

The integer that is returned by HSBtoRGB encodes the value of a color in bits 0&endash;23 of an integer value, 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.

Parameters:
hue - the hue component of the color.
saturation - the saturation of the color.
brightness - the brightness of the color.
Returns:
the RGB value of the color with the indicated hue, saturation, and brightness.
Since:
JDK1.0
See Also:
getRGB(), Color(int)
 o RGBtoHSB
public static float[] RGBtoHSB(int r,
                               int g,
                               int b,
                               float hsbvals)
Converts the components of a color, as specified by the RGB model, to an equivalent set of values for hue, saturation, and brightness, 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.

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 three HSB values, or null.
Returns:
an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
Since:
JDK1.0
See Also:
getRGB(), Color(int)
 o brighter
public java.awt.Color brighter()
Creates a brighter version of this color.

This method applies an arbitrary scale factor to each of the three RGB components of the color to create a brighter version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Returns:
a new Color object, a brighter version of this color.
Since:
JDK1.0
See Also:
darker
 o darker
public java.awt.Color darker()
Creates a darker version of this color.

This method applies an arbitrary scale factor to each of the three RGB components of the color to create a darker version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Returns:
a new Color object, a darker version of this color.
Since:
JDK1.0
See Also:
brighter
 o decode
public static java.awt.Color decode(String nm) throws NumberFormatException
Converts a string to an integer and returns the specified color. This method handles string formats that are used to represent octal and hexidecimal numbers.

Parameters:
nm - a string that represents a color as a 24-bit integer.
Returns:
the new color
Throws: NumberFormatException
if the specified string cannot be interpreted as a decimal, octal, or hexidecimal integer.
Since:
JDK1.1
See Also:
decode
 o equals
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, and blue values 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
Since:
JDK1.0
 o getBlue
public int getBlue()
Gets the blue component of this color. The result is an integer in the range 0 to 255.

Returns:
the blue component of this color.
Since:
JDK1.0
See Also:
getRGB
 o getColor
public static java.awt.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.

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

Parameters:
nm - the name of the color property
Returns:
the color value of the property.
Since:
JDK1.0
See Also:
getProperty(java.lang.String), getInteger(java.lang.String), Color(int)
 o getColor
public static java.awt.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.

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.

Parameters:
nm - the name of the color property
v - the default color value.
Returns:
the color value of the property.
Since:
JDK1.0
See Also:
getProperty(java.lang.String), getInteger(java.lang.String), Color(int)
 o getColor
public static java.awt.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.

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.

Parameters:
nm - the name of the color property.
v - the default color value, as an integer.
Returns:
the color value of the property.
Since:
JDK1.0
See Also:
getProperty(java.lang.String), getInteger(java.lang.String), Color(int)
 o getGreen
public int getGreen()
Gets the green component of this color. The result is an integer in the range 0 to 255.

Returns:
the green component of this color.
Since:
JDK1.0
See Also:
getRGB
 o getHSBColor
public static java.awt.Color getHSBColor(float h,
                                         float s,
                                         float b)
Creates a Color object based on values supplied for the HSB color model.

Each of the three components should be a floating-point value between zero and one (a number in the range 0.0 ≤ h, s, b ≤ 1.0).

Parameters:
h - the hue component.
s - the saturation of the color.
b - the brightness of the color.
Returns:
a Color object with the specified hue, saturation, and brightness.
Since:
JDK1.0
 o getRGB
public int getRGB()
Gets the RGB value representing the color in the default RGB ColorModel. The red, green, and blue components of the color are each scaled to be a value between 0 (abscence of the color) and 255 (complete saturation). Bits 24-31 of the returned integer are 0xff, bits 16-23 are the red value, bit 8-15 are the green value, and bits 0-7 are the blue value.

Since:
JDK1.0
See Also:
getRGBdefault, getRed, getGreen, getBlue
 o getRed
public int getRed()
Gets the red component of this color. The result is an integer in the range 0 to 255.

Returns:
the red component of this color.
Since:
JDK1.0
See Also:
getRGB
 o hashCode
public int hashCode()
Computes the hash code for this color.

Returns:
a hash code value for this object.
Overrides:
hashCode in class Object
Since:
JDK1.0
 o toString
public java.lang.String toString()
Creates a string that represents this color and indicates the values of its RGB components.

Returns:
a representation of this color as a String object.
Overrides:
toString in class Object
Since:
JDK1.0

All Packages  Class Hierarchy  This Package  Previous  Next  Index