java awt Color








Class java.awt.Color





All Packages Class Hierarchy This Package Previous Next Index


Class java.awt.Color


java.lang.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.








black
The color black.

blue
The color blue.

cyan
The color cyan.

darkGray
The color dark gray.

gray
The color gray.

green
The color green.

lightGray
The color light gray.

magenta
The color magenta.

orange
The color orange.

pink
The color pink.

red
The color red.

white
The color white.

yellow
The color yellow.






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.

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.

Color(int, int, int)
Creates a color with the specified red, green, and blue
components.






brighter()
Creates a brighter version of this color.

darker()
Creates a darker version of this color.

decode(String)
Converts a string to an integer and returns the
specified color.

equals(Object)
Determines whether another object is equal to this color.

getBlue()
Gets the blue component of this color.

getColor(String)
Finds a color in the system properties.

getColor(String, Color)
Finds a color in the system properties.

getColor(String, int)
Finds a color in the system properties.

getGreen()
Gets the green component of this color.

getHSBColor(float, float, float)
Creates a Color object based on values supplied
for the HSB color model.

getRed()
Gets the red component of this color.

getRGB()
Gets the RGB value representing the color in the default RGB ColorModel.

hashCode()
Computes the hash code for this color.

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.

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.

toString()
Creates a string that represents this color and indicates the
values of its RGB components.






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 magenta.


cyan

public static final Color cyan


The color cyan.


blue

public static final Color blue


The color blue.







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.
See Also:
getRed., getGreen., getBlue., getRGB.



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.
See Also:
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,
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
See Also:
getRed., getGreen., getBlue., getRGB.







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.
See Also:
getRGB



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.
See Also:
getRGB



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.
See Also:
getRGB



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.


See Also:
getRGBdefault, getRed, getGreen, getBlue



brighter

public 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.
See Also:
darker



darker

public 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.
See Also:
brighter



hashCode

public int hashCode()


Computes the hash code for this color.


Returns:
a hash code value for this object.
Overrides:
hashCode in class Object



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



toString

public 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



decode

public static 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.
See Also:
decode



getColor

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.

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.
See Also:
getProperty, getInteger, Color



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. 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.
See Also:
getProperty, getInteger, Color



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. 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.
See Also:
getProperty, getInteger, Color



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.
See Also:
getRGB, Color



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.
See Also:
getRGB, Color



getHSBColor

public static 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.




All Packages Class Hierarchy This Package Previous Next Index

Submit a bug or feature - Version 1.1.7 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.




Wyszukiwarka

Podobne podstrony:
java awt image IndexColorModel
java awt image ImageConsumer
java awt event ActionEvent
java awt event FocusEvent
java awt IllegalComponentStateException
java awt Label
java awt Menu
java awt image ReplicateScaleFilter
java awt Cursor
java awt datatransfer ClipboardOwner
java awt Toolkit
java awt event MouseMotionListener
java awt datatransfer StringSelection
java awt Shape
java awt Choice
java awt event WindowEvent
java awt image ColorModel
java awt EventQueue
java awt event ComponentEvent

więcej podobnych podstron