Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public final class java.awt.Color extends java.lang.Object { // Fields public final static Color black; public final static Color blue; public final static Color cyan; public final static Color darkGray; public final static Color gray; public final static Color green; public final static Color lightGray; public final static Color magenta; public final static Color orange; public final static Color pink; public final static Color red; public final static Color white; public final static Color yellow; // Constructors public Color(float r, float g, float b); public Color(int rgb); public Color(int r, int g, int b); // Methods public Color brighter(); public Color darker(); public boolean equals(Object obj); public int getBlue(); public static Color getColor(String nm); public static Color getColor(String nm, Color v); public static Color getColor(String nm, int v); public int getGreen(); public static Color getHSBColor(float h, float s, float b); public int getRed(); public int getRGB(); public int hashCode(); public static int HSBtoRGB(float hue, float saturation, float brightness); public static float[] RGBtoHSB(int r, int g, int b, float hsbvals[]); public String toString(); }
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.
public final static Color black = new Color(0, 0, 0)The color black.
public final static Color blue = new Color(0, 0, 255)The color blue.
public final static Color cyan = new Color(0, 255, 255)The color cyan.
public final static Color darkGray = new Color(64, 64, 64)The color dark gray.
public final static Color gray = new Color(128, 128, 128)The color gray.
public final static Color green = new Color(0, 255, 0);The color green.
public final static Color lightGray= new Color(192, 192, 192)The color light gray.
public final static Color magenta = new Color(255, 0, 255)The color magneta.
public final static Color orange = new Color(255, 200, 0)The color orange.
public final static Color pink = new Color(255, 175, 175)The color pink.
public final static Color red = new Color(255, 0, 0)The color red.
public final static Color white = new Color(255, 255, 255)The color white.
public final static Color yellow = new Color(255, 255, 0)The color yellow.
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.
Parameter Description r the red component g the red component b the red component
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.
Parameter Description rgb an integer giving the red, green, and blue components See Also: getRGBdefault in class ColorModel .
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.
Parameter Description r the red component g the green component b the blue component
public Color brighter()Return Value:
Returns a brighter version of this color.
public Color darker()Return Value:
Returns a darker version of this color.
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.
Return Value:
Returns true if the objects are the same; false otherwise.
Parameter Description obj the object to compare with Overrides:
equals in class Object .
public int getBlue()Returns the blue component of this color. The result is in the range 0 to 255.
Return Value:
Returns the blue component of this color.
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 . The string value of this property is then interpreted as an integer value (see Integer.getInteger 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 .
If the specified property is not found, or could not be parsed as an integer, then null is returned.
Return Value:
Returns the color value of the property.
Parameter Description nm the property name
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 . The string value of this property is then interpreted as an integer value (see Integer.getInteger 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 .
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.
Return Value:
Returns the Color value of the property.
Parameter Description nm the property name v default Color value
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 . The string value of this property is then interpreted as an integer value (see Integer.getInteger 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 .
Return Value:
Returns the new color.
Parameter Description nm the property name v the default color value
public int getGreen()Returns the green component of this color. The result is in the range 0 to 255.
Return Value:
Returns the green component of this color.
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 0.0 £ h, s, b, £ 1.0.
Return Value:
Returns the color object with the specified hue, saturation, and brightness.
Parameter Description h the hue component s the saturation of the color b the brightness of the color
public int getRed()Returns the red component of this color. The result is in the range 0 to 255.
Return Value:
Returns the red component of this color
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.
Return Value:
Returns an integer representing this color.
See Also: getRGBdefault in class ColorModel .
public int hashCode()Return Value:
Returns a hash code value for this object.
Overrides:
hashCode in class Object .
public static int HSBtoRGB(float hue, float saturation, float brightness)Converts a color specified by hue, saturation, and brightness, to a corresponding RGB value.
Return Value:
Returns the RGB value of the color with the indicated hue, saturation, and brightness.
Parameter Description hue the hue component of the color saturation the saturation of the color brightness the brightness of the color
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.
Return Value:
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.
Parameter Description 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 See Also: getRGBdefault in class ColorModel getRGB .
public String toString()Return Value:
Returns a string representation of this color.
Overrides:
toString in class Object .