java.awt
Class Color

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.Color
All Implemented Interfaces:
Paint sample code for java.awt.Paint definition code for java.awt.Paint , Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency , Serializable sample code for java.io.Serializable definition code for java.io.Serializable
Direct Known Subclasses:
ColorUIResource sample code for javax.swing.plaf.ColorUIResource definition code for javax.swing.plaf.ColorUIResource , SystemColor sample code for java.awt.SystemColor definition code for java.awt.SystemColor

public class Color
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Paint sample code for java.awt.Paint definition code for java.awt.Paint , Serializable sample code for java.io.Serializable definition code for java.io.Serializable

The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary color spaces identified by a ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.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 .

See Also:
ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.ColorSpace , AlphaComposite sample code for java.awt.AlphaComposite definition code for java.awt.AlphaComposite , Serialized Form

Field Summary
static Color sample code for java.awt.Color definition code for java.awt.Color black sample code for java.awt.Color.black definition code for java.awt.Color.black
          The color black.
static Color sample code for java.awt.Color definition code for java.awt.Color BLACK sample code for java.awt.Color.BLACK definition code for java.awt.Color.BLACK
          The color black.
static Color sample code for java.awt.Color definition code for java.awt.Color blue sample code for java.awt.Color.blue definition code for java.awt.Color.blue
          The color blue.
static Color sample code for java.awt.Color definition code for java.awt.Color BLUE sample code for java.awt.Color.BLUE definition code for java.awt.Color.BLUE
          The color blue.
static Color sample code for java.awt.Color definition code for java.awt.Color cyan sample code for java.awt.Color.cyan definition code for java.awt.Color.cyan
          The color cyan.
static Color sample code for java.awt.Color definition code for java.awt.Color CYAN sample code for java.awt.Color.CYAN definition code for java.awt.Color.CYAN
          The color cyan.
static Color sample code for java.awt.Color definition code for java.awt.Color DARK_GRAY sample code for java.awt.Color.DARK_GRAY definition code for java.awt.Color.DARK_GRAY
          The color dark gray.
static Color sample code for java.awt.Color definition code for java.awt.Color darkGray sample code for java.awt.Color.darkGray definition code for java.awt.Color.darkGray
          The color dark gray.
static Color sample code for java.awt.Color definition code for java.awt.Color gray sample code for java.awt.Color.gray definition code for java.awt.Color.gray
          The color gray.
static Color sample code for java.awt.Color definition code for java.awt.Color GRAY sample code for java.awt.Color.GRAY definition code for java.awt.Color.GRAY
          The color gray.
static Color sample code for java.awt.Color definition code for java.awt.Color green sample code for java.awt.Color.green definition code for java.awt.Color.green
          The color green.
static Color sample code for java.awt.Color definition code for java.awt.Color GREEN sample code for java.awt.Color.GREEN definition code for java.awt.Color.GREEN
          The color green.
static Color sample code for java.awt.Color definition code for java.awt.Color LIGHT_GRAY sample code for java.awt.Color.LIGHT_GRAY definition code for java.awt.Color.LIGHT_GRAY
          The color light gray.
static Color sample code for java.awt.Color definition code for java.awt.Color lightGray sample code for java.awt.Color.lightGray definition code for java.awt.Color.lightGray
          The color light gray.
static Color sample code for java.awt.Color definition code for java.awt.Color magenta sample code for java.awt.Color.magenta definition code for java.awt.Color.magenta
          The color magenta.
static Color sample code for java.awt.Color definition code for java.awt.Color MAGENTA sample code for java.awt.Color.MAGENTA definition code for java.awt.Color.MAGENTA
          The color magenta.
static Color sample code for java.awt.Color definition code for java.awt.Color orange sample code for java.awt.Color.orange definition code for java.awt.Color.orange
          The color orange.
static Color sample code for java.awt.Color definition code for java.awt.Color ORANGE sample code for java.awt.Color.ORANGE definition code for java.awt.Color.ORANGE
          The color orange.
static Color sample code for java.awt.Color definition code for java.awt.Color pink sample code for java.awt.Color.pink definition code for java.awt.Color.pink
          The color pink.
static Color sample code for java.awt.Color definition code for java.awt.Color PINK sample code for java.awt.Color.PINK definition code for java.awt.Color.PINK
          The color pink.
static Color sample code for java.awt.Color definition code for java.awt.Color red sample code for java.awt.Color.red definition code for java.awt.Color.red
          The color red.
static Color sample code for java.awt.Color definition code for java.awt.Color RED sample code for java.awt.Color.RED definition code for java.awt.Color.RED
          The color red.
static Color sample code for java.awt.Color definition code for java.awt.Color white sample code for java.awt.Color.white definition code for java.awt.Color.white
          The color white.
static Color sample code for java.awt.Color definition code for java.awt.Color WHITE sample code for java.awt.Color.WHITE definition code for java.awt.Color.WHITE
          The color white.
static Color sample code for java.awt.Color definition code for java.awt.Color yellow sample code for java.awt.Color.yellow definition code for java.awt.Color.yellow
          The color yellow.
static Color sample code for java.awt.Color definition code for java.awt.Color YELLOW sample code for java.awt.Color.YELLOW definition code for java.awt.Color.YELLOW
          The color yellow.
 
Fields inherited from interface java.awt.Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency
BITMASK sample code for java.awt.Transparency.BITMASK definition code for java.awt.Transparency.BITMASK , OPAQUE sample code for java.awt.Transparency.OPAQUE definition code for java.awt.Transparency.OPAQUE , TRANSLUCENT sample code for java.awt.Transparency.TRANSLUCENT definition code for java.awt.Transparency.TRANSLUCENT
 
Constructor Summary
Color sample code for java.awt.Color.Color(java.awt.color.ColorSpace, float[], float) definition code for java.awt.Color.Color(java.awt.color.ColorSpace, float[], float) (ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.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.
Color sample code for java.awt.Color.Color(float, float, float) definition code for java.awt.Color.Color(float, float, float) (float r, float g, float b)
          Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).
Color sample code for java.awt.Color.Color(float, float, float, float) definition code for java.awt.Color.Color(float, float, float, float) (float r, float g, float b, float a)
          Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).
Color sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int) (int rgb)
          Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color sample code for java.awt.Color.Color(int, boolean) definition code for java.awt.Color.Color(int, boolean) (int rgba, boolean hasalpha)
          Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color sample code for java.awt.Color.Color(int, int, int) definition code for java.awt.Color.Color(int, int, int) (int r, int g, int b)
          Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).
Color sample code for java.awt.Color.Color(int, int, int, int) definition code for java.awt.Color.Color(int, int, int, int) (int r, int g, int b, int a)
          Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
 
Method Summary
 Color sample code for java.awt.Color definition code for java.awt.Color brighter sample code for java.awt.Color.brighter() definition code for java.awt.Color.brighter() ()
          Creates a new Color that is a brighter version of this Color.
 PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext createContext sample code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) (ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel  cm, Rectangle sample code for java.awt.Rectangle definition code for java.awt.Rectangle  r, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  r2d, AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  xform, RenderingHints sample code for java.awt.RenderingHints definition code for java.awt.RenderingHints  hints)
          Creates and returns a PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext used to generate a solid color pattern.
 Color sample code for java.awt.Color definition code for java.awt.Color darker sample code for java.awt.Color.darker() definition code for java.awt.Color.darker() ()
          Creates a new Color that is a darker version of this Color.
static Color sample code for java.awt.Color definition code for java.awt.Color decode sample code for java.awt.Color.decode(java.lang.String) definition code for java.awt.Color.decode(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  nm)
          Converts a String to an integer and returns the specified opaque Color.
 boolean equals sample code for java.awt.Color.equals(java.lang.Object) definition code for java.awt.Color.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Determines whether another object is equal to this Color.
 int getAlpha sample code for java.awt.Color.getAlpha() definition code for java.awt.Color.getAlpha() ()
          Returns the alpha component in the range 0-255.
 int getBlue sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() ()
          Returns the blue component in the range 0-255 in the default sRGB space.
static Color sample code for java.awt.Color definition code for java.awt.Color getColor sample code for java.awt.Color.getColor(java.lang.String) definition code for java.awt.Color.getColor(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  nm)
          Finds a color in the system properties.
static Color sample code for java.awt.Color definition code for java.awt.Color getColor sample code for java.awt.Color.getColor(java.lang.String, java.awt.Color) definition code for java.awt.Color.getColor(java.lang.String, java.awt.Color) (String sample code for java.lang.String definition code for java.lang.String  nm, Color sample code for java.awt.Color definition code for java.awt.Color  v)
          Finds a color in the system properties.
static Color sample code for java.awt.Color definition code for java.awt.Color getColor sample code for java.awt.Color.getColor(java.lang.String, int) definition code for java.awt.Color.getColor(java.lang.String, int) (String sample code for java.lang.String definition code for java.lang.String  nm, int v)
          Finds a color in the system properties.
 float[] getColorComponents sample code for java.awt.Color.getColorComponents(java.awt.color.ColorSpace, float[]) definition code for java.awt.Color.getColorComponents(java.awt.color.ColorSpace, float[]) (ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.ColorSpace  cspace, float[] compArray)
          Returns a float array containing only the color components of the Color in the ColorSpace specified by the cspace parameter.
 float[] getColorComponents sample code for java.awt.Color.getColorComponents(float[]) definition code for java.awt.Color.getColorComponents(float[]) (float[] compArray)
          Returns a float array containing only the color components of the Color, in the ColorSpace of the Color.
 ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.ColorSpace getColorSpace sample code for java.awt.Color.getColorSpace() definition code for java.awt.Color.getColorSpace() ()
          Returns the ColorSpace of this Color.
 float[] getComponents sample code for java.awt.Color.getComponents(java.awt.color.ColorSpace, float[]) definition code for java.awt.Color.getComponents(java.awt.color.ColorSpace, float[]) (ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.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.
 float[] getComponents sample code for java.awt.Color.getComponents(float[]) definition code for java.awt.Color.getComponents(float[]) (float[] compArray)
          Returns a float array containing the color and alpha components of the Color, in the ColorSpace of the Color.
 int getGreen sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() ()
          Returns the green component in the range 0-255 in the default sRGB space.
static Color sample code for java.awt.Color definition code for java.awt.Color getHSBColor sample code for java.awt.Color.getHSBColor(float, float, float) definition code for java.awt.Color.getHSBColor(float, float, float) (float h, float s, float b)
          Creates a Color object based on the specified values for the HSB color model.
 int getRed sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() ()
          Returns the red component in the range 0-255 in the default sRGB space.
 int getRGB sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB() ()
          Returns the RGB value representing the color in the default sRGB ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel .
 float[] getRGBColorComponents sample code for java.awt.Color.getRGBColorComponents(float[]) definition code for java.awt.Color.getRGBColorComponents(float[]) (float[] compArray)
          Returns a float array containing only the color components of the Color, in the default sRGB color space.
 float[] getRGBComponents sample code for java.awt.Color.getRGBComponents(float[]) definition code for java.awt.Color.getRGBComponents(float[]) (float[] compArray)
          Returns a float array containing the color and alpha components of the Color, as represented in the default sRGB color space.
 int getTransparency sample code for java.awt.Color.getTransparency() definition code for java.awt.Color.getTransparency() ()
          Returns the transparency mode for this Color.
 int hashCode sample code for java.awt.Color.hashCode() definition code for java.awt.Color.hashCode() ()
          Computes the hash code for this Color.
static int HSBtoRGB sample code for java.awt.Color.HSBtoRGB(float, float, float) definition code for java.awt.Color.HSBtoRGB(float, float, float) (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.
static float[] RGBtoHSB sample code for java.awt.Color.RGBtoHSB(int, int, int, float[]) definition code for java.awt.Color.RGBtoHSB(int, int, int, float[]) (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.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.Color.toString() definition code for java.awt.Color.toString() ()
          Returns a string representation of this Color.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

white sample code for java.awt.Color.white

public static final Color sample code for java.awt.Color definition code for java.awt.Color  white
The color white. In the default sRGB space.


WHITE sample code for java.awt.Color.WHITE

public static final Color sample code for java.awt.Color definition code for java.awt.Color  WHITE
The color white. In the default sRGB space.


lightGray sample code for java.awt.Color.lightGray

public static final Color sample code for java.awt.Color definition code for java.awt.Color  lightGray
The color light gray. In the default sRGB space.


LIGHT_GRAY sample code for java.awt.Color.LIGHT_GRAY

public static final Color sample code for java.awt.Color definition code for java.awt.Color  LIGHT_GRAY
The color light gray. In the default sRGB space.


gray sample code for java.awt.Color.gray

public static final Color sample code for java.awt.Color definition code for java.awt.Color  gray
The color gray. In the default sRGB space.


GRAY sample code for java.awt.Color.GRAY

public static final Color sample code for java.awt.Color definition code for java.awt.Color  GRAY
The color gray. In the default sRGB space.


darkGray sample code for java.awt.Color.darkGray

public static final Color sample code for java.awt.Color definition code for java.awt.Color  darkGray
The color dark gray. In the default sRGB space.


DARK_GRAY sample code for java.awt.Color.DARK_GRAY

public static final Color sample code for java.awt.Color definition code for java.awt.Color  DARK_GRAY
The color dark gray. In the default sRGB space.


black sample code for java.awt.Color.black

public static final Color sample code for java.awt.Color definition code for java.awt.Color  black
The color black. In the default sRGB space.


BLACK sample code for java.awt.Color.BLACK

public static final Color sample code for java.awt.Color definition code for java.awt.Color  BLACK
The color black. In the default sRGB space.


red sample code for java.awt.Color.red

public static final Color sample code for java.awt.Color definition code for java.awt.Color  red
The color red. In the default sRGB space.


RED sample code for java.awt.Color.RED

public static final Color sample code for java.awt.Color definition code for java.awt.Color  RED
The color red. In the default sRGB space.


pink sample code for java.awt.Color.pink

public static final Color sample code for java.awt.Color definition code for java.awt.Color  pink
The color pink. In the default sRGB space.


PINK sample code for java.awt.Color.PINK

public static final Color sample code for java.awt.Color definition code for java.awt.Color  PINK
The color pink. In the default sRGB space.


orange sample code for java.awt.Color.orange

public static final Color sample code for java.awt.Color definition code for java.awt.Color  orange
The color orange. In the default sRGB space.


ORANGE sample code for java.awt.Color.ORANGE

public static final Color sample code for java.awt.Color definition code for java.awt.Color  ORANGE
The color orange. In the default sRGB space.


yellow sample code for java.awt.Color.yellow

public static final Color sample code for java.awt.Color definition code for java.awt.Color  yellow
The color yellow. In the default sRGB space.


YELLOW sample code for java.awt.Color.YELLOW

public static final Color sample code for java.awt.Color definition code for java.awt.Color  YELLOW
The color yellow. In the default sRGB space.


green sample code for java.awt.Color.green

public static final Color sample code for java.awt.Color definition code for java.awt.Color  green
The color green. In the default sRGB space.


GREEN sample code for java.awt.Color.GREEN

public static final Color sample code for java.awt.Color definition code for java.awt.Color  GREEN
The color green. In the default sRGB space.


magenta sample code for java.awt.Color.magenta

public static final Color sample code for java.awt.Color definition code for java.awt.Color  magenta
The color magenta. In the default sRGB space.


MAGENTA sample code for java.awt.Color.MAGENTA

public static final Color sample code for java.awt.Color definition code for java.awt.Color  MAGENTA
The color magenta. In the default sRGB space.


cyan sample code for java.awt.Color.cyan

public static final Color sample code for java.awt.Color definition code for java.awt.Color  cyan
The color cyan. In the default sRGB space.


CYAN sample code for java.awt.Color.CYAN

public static final Color sample code for java.awt.Color definition code for java.awt.Color  CYAN
The color cyan. In the default sRGB space.


blue sample code for java.awt.Color.blue

public static final Color sample code for java.awt.Color definition code for java.awt.Color  blue
The color blue. In the default sRGB space.


BLUE sample code for java.awt.Color.BLUE

public static final Color sample code for java.awt.Color definition code for java.awt.Color  BLUE
The color blue. In the default sRGB space.

Constructor Detail

Color sample code for java.awt.Color(int, int, int) definition code for java.awt.Color(int, int, int)

public Color(int r,
             int g,
             int b)
Creates an opaque sRGB color with the specified red, green, and blue values 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. Alpha is defaulted to 255.

Parameters:
r - the red component
g - the green component
b - the blue component
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if r, g or b are outside of the range 0 to 255, inclusive
See Also:
getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(int, int, int, int) definition code for java.awt.Color(int, int, int, int)

public Color(int r,
             int g,
             int b,
             int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).

Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if r, g, b or a are outside of the range 0 to 255, inclusive
See Also:
getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getAlpha() sample code for java.awt.Color.getAlpha() definition code for java.awt.Color.getAlpha() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(int) definition code for java.awt.Color(int)

public Color(int rgb)
Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.

Parameters:
rgb - the combined RGB components
See Also:
ColorModel.getRGBdefault() sample code for java.awt.image.ColorModel.getRGBdefault() definition code for java.awt.image.ColorModel.getRGBdefault() , getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(int, boolean) definition code for java.awt.Color(int, boolean)

public Color(int rgba,
             boolean hasalpha)
Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. If the hasalpha argument is false, alpha is defaulted to 255.

Parameters:
rgba - the combined RGBA components
hasalpha - true if the alpha bits are valid; false otherwise
See Also:
ColorModel.getRGBdefault() sample code for java.awt.image.ColorModel.getRGBdefault() definition code for java.awt.image.ColorModel.getRGBdefault() , getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getAlpha() sample code for java.awt.Color.getAlpha() definition code for java.awt.Color.getAlpha() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(float, float, float) definition code for java.awt.Color(float, float, float)

public Color(float r,
             float g,
             float b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). Alpha is defaulted to 1.0. The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r - the red component
g - the green component
b - the blue component
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if r, g or b are outside of the range 0.0 to 1.0, inclusive
See Also:
getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(float, float, float, float) definition code for java.awt.Color(float, float, float, float)

public Color(float r,
             float g,
             float b,
             float a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if r, g b or a are outside of the range 0.0 to 1.0, inclusive
See Also:
getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue() , getAlpha() sample code for java.awt.Color.getAlpha() definition code for java.awt.Color.getAlpha() , getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

Color sample code for java.awt.Color(java.awt.color.ColorSpace, float[], float) definition code for java.awt.Color(java.awt.color.ColorSpace, float[], float)

public Color(ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.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
alpha - alpha value
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if any of the values in the components array or alpha is outside of the range 0.0 to 1.0
See Also:
getComponents(float[]) sample code for java.awt.Color.getComponents(float[]) definition code for java.awt.Color.getComponents(float[]) , getColorComponents(float[]) sample code for java.awt.Color.getColorComponents(float[]) definition code for java.awt.Color.getColorComponents(float[])
Method Detail

getRed sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed()

public int getRed()
Returns the red component in the range 0-255 in the default sRGB space.

Returns:
the red component.
See Also:
getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

getGreen sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen()

public int getGreen()
Returns the green component in the range 0-255 in the default sRGB space.

Returns:
the green component.
See Also:
getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

getBlue sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue()

public int getBlue()
Returns the blue component in the range 0-255 in the default sRGB space.

Returns:
the blue component.
See Also:
getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

getAlpha sample code for java.awt.Color.getAlpha() definition code for java.awt.Color.getAlpha()

public int getAlpha()
Returns the alpha component in the range 0-255.

Returns:
the alpha component.
See Also:
getRGB() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

getRGB sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB()

public int getRGB()
Returns the RGB value representing the color in the default sRGB ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel . (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).

Returns:
the RGB value of the color in the default sRGB ColorModel.
Since:
JDK1.0
See Also:
ColorModel.getRGBdefault() sample code for java.awt.image.ColorModel.getRGBdefault() definition code for java.awt.image.ColorModel.getRGBdefault() , getRed() sample code for java.awt.Color.getRed() definition code for java.awt.Color.getRed() , getGreen() sample code for java.awt.Color.getGreen() definition code for java.awt.Color.getGreen() , getBlue() sample code for java.awt.Color.getBlue() definition code for java.awt.Color.getBlue()

brighter sample code for java.awt.Color.brighter() definition code for java.awt.Color.brighter()

public Color sample code for java.awt.Color definition code for java.awt.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. 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.

Returns:
a new Color object that is a brighter version of this Color.
Since:
JDK1.0
See Also:
darker() sample code for java.awt.Color.darker() definition code for java.awt.Color.darker()

darker sample code for java.awt.Color.darker() definition code for java.awt.Color.darker()

public Color sample code for java.awt.Color definition code for java.awt.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. 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.

Returns:
a new Color object that is a darker version of this Color.
Since:
JDK1.0
See Also:
brighter() sample code for java.awt.Color.brighter() definition code for java.awt.Color.brighter()

hashCode sample code for java.awt.Color.hashCode() definition code for java.awt.Color.hashCode()

public int hashCode()
Computes the hash code for this Color.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a hash code value for this object.
Since:
JDK1.0
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.awt.Color.equals(java.lang.Object) definition code for java.awt.Color.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.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.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the object to test for equality with this Color
Returns:
true if the objects are the same; false otherwise.
Since:
JDK1.0
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

toString sample code for java.awt.Color.toString() definition code for java.awt.Color.toString()

public String sample code for java.lang.String definition code for java.lang.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.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of this Color.

decode sample code for java.awt.Color.decode(java.lang.String) definition code for java.awt.Color.decode(java.lang.String)

public static Color sample code for java.awt.Color definition code for java.awt.Color  decode(String sample code for java.lang.String definition code for java.lang.String  nm)
                    throws NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.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 hexidecimal numbers.

Parameters:
nm - a String that represents an opaque color as a 24-bit integer
Returns:
the new Color object.
Throws:
NumberFormatException sample code for java.lang.NumberFormatException definition code for java.lang.NumberFormatException - if the specified string cannot be interpreted as a decimal, octal, or hexidecimal integer.
Since:
JDK1.1
See Also:
Integer.decode(java.lang.String) sample code for java.lang.Integer.decode(java.lang.String) definition code for java.lang.Integer.decode(java.lang.String)

getColor sample code for java.awt.Color.getColor(java.lang.String) definition code for java.awt.Color.getColor(java.lang.String)

public static Color sample code for java.awt.Color definition code for java.awt.Color  getColor(String sample code for java.lang.String definition code for java.lang.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.

Parameters:
nm - the name of the color property
Returns:
the Color converted from the system property.
Since:
JDK1.0
See Also:
System.getProperty(java.lang.String) sample code for java.lang.System.getProperty(java.lang.String) definition code for java.lang.System.getProperty(java.lang.String) , Integer.getInteger(java.lang.String) sample code for java.lang.Integer.getInteger(java.lang.String) definition code for java.lang.Integer.getInteger(java.lang.String) , Color(int) sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int)

getColor sample code for java.awt.Color.getColor(java.lang.String, java.awt.Color) definition code for java.awt.Color.getColor(java.lang.String, java.awt.Color)

public static Color sample code for java.awt.Color definition code for java.awt.Color  getColor(String sample code for java.lang.String definition code for java.lang.String  nm,
                             Color sample code for java.awt.Color definition code for java.awt.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.

Parameters:
nm - the name of the color property
v - the default Color
Returns:
the Color converted from the system property, or the specified Color.
Since:
JDK1.0
See Also:
System.getProperty(java.lang.String) sample code for java.lang.System.getProperty(java.lang.String) definition code for java.lang.System.getProperty(java.lang.String) , Integer.getInteger(java.lang.String) sample code for java.lang.Integer.getInteger(java.lang.String) definition code for java.lang.Integer.getInteger(java.lang.String) , Color(int) sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int)

getColor sample code for java.awt.Color.getColor(java.lang.String, int) definition code for java.awt.Color.getColor(java.lang.String, int)

public static Color sample code for java.awt.Color definition code for java.awt.Color  getColor(String sample code for java.lang.String definition code for java.lang.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.

Parameters:
nm - the name of the color property
v - the default color value, as an integer
Returns:
the Color converted from the system property or the Color converted from the specified integer.
Since:
JDK1.0
See Also:
System.getProperty(java.lang.String) sample code for java.lang.System.getProperty(java.lang.String) definition code for java.lang.System.getProperty(java.lang.String) , Integer.getInteger(java.lang.String) sample code for java.lang.Integer.getInteger(java.lang.String) definition code for java.lang.Integer.getInteger(java.lang.String) , Color(int) sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int)

HSBtoRGB sample code for java.awt.Color.HSBtoRGB(float, float, float) definition code for java.awt.Color.HSBtoRGB(float, float, float)

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 sample code for java.awt.Color.getRGB() definition code for java.awt.Color.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() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB() , Color(int) sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int) , ColorModel.getRGBdefault() sample code for java.awt.image.ColorModel.getRGBdefault() definition code for java.awt.image.ColorModel.getRGBdefault()

RGBtoHSB sample code for java.awt.Color.RGBtoHSB(int, int, int, float[]) definition code for java.awt.Color.RGBtoHSB(int, int, int, float[])

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.

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 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() sample code for java.awt.Color.getRGB() definition code for java.awt.Color.getRGB() , Color(int) sample code for java.awt.Color.Color(int) definition code for java.awt.Color.Color(int) , ColorModel.getRGBdefault() sample code for java.awt.image.ColorModel.getRGBdefault() definition code for java.awt.image.ColorModel.getRGBdefault()

getHSBColor sample code for java.awt.Color.getHSBColor(float, float, float) definition code for java.awt.Color.getHSBColor(float, float, float)

public static Color sample code for java.awt.Color definition code for java.awt.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.

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

getRGBComponents sample code for java.awt.Color.getRGBComponents(float[]) definition code for java.awt.Color.getRGBComponents(float[])

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.

Parameters:
compArray - an array that this method fills with color and alpha components and returns
Returns:
the RGBA components in a float array.

getRGBColorComponents sample code for java.awt.Color.getRGBColorComponents(float[]) definition code for java.awt.Color.getRGBColorComponents(float[])

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.

Parameters:
compArray - an array that this method fills with color components and returns
Returns:
the RGB components in a float array.

getComponents sample code for java.awt.Color.getComponents(float[]) definition code for java.awt.Color.getComponents(float[])

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.

Parameters:
compArray - an array that this method fills with the color and alpha components of this Color in its ColorSpace and returns
Returns:
the color and alpha components in a float array.

getColorComponents sample code for java.awt.Color.getColorComponents(float[]) definition code for java.awt.Color.getColorComponents(float[])

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.

Parameters:
compArray - an array that this method fills with the color components of this Color in its ColorSpace and returns
Returns:
the color components in a float array.

getComponents sample code for java.awt.Color.getComponents(java.awt.color.ColorSpace, float[]) definition code for java.awt.Color.getComponents(java.awt.color.ColorSpace, float[])

public float[] getComponents(ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.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.

Parameters:
cspace - a specified ColorSpace
compArray - an array that this method fills with the color and alpha components of this Color in the specified ColorSpace and returns
Returns:
the color and alpha components in a float array.

getColorComponents sample code for java.awt.Color.getColorComponents(java.awt.color.ColorSpace, float[]) definition code for java.awt.Color.getColorComponents(java.awt.color.ColorSpace, float[])

public float[] getColorComponents(ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.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.

Parameters:
cspace - a specified ColorSpace
compArray - an array that this method fills with the color components of this Color in the specified ColorSpace
Returns:
the color components in a float array.

getColorSpace sample code for java.awt.Color.getColorSpace() definition code for java.awt.Color.getColorSpace()

public ColorSpace sample code for java.awt.color.ColorSpace definition code for java.awt.color.ColorSpace  getColorSpace()
Returns the ColorSpace of this Color.

Returns:
this Color object's ColorSpace.

createContext sample code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints)

public PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext  createContext(ColorModel sample code for java.awt.image.ColorModel definition code for java.awt.image.ColorModel  cm,
                                  Rectangle sample code for java.awt.Rectangle definition code for java.awt.Rectangle  r,
                                  Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  r2d,
                                  AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  xform,
                                  RenderingHints sample code for java.awt.RenderingHints definition code for java.awt.RenderingHints  hints)
Creates and returns a PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext used to generate a solid color pattern. This enables a Color object to be used as an argument to any method requiring an object implementing the Paint sample code for java.awt.Paint definition code for java.awt.Paint interface. The same PaintContext is returned, regardless of whether or not r, r2d, xform, or hints are null.

Specified by:
createContext sample code for java.awt.Paint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.Paint.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) in interface Paint sample code for java.awt.Paint definition code for java.awt.Paint
Parameters:
cm - the specified ColorModel
r - the specified Rectangle sample code for java.awt.Rectangle definition code for java.awt.Rectangle
r2d - the specified Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D
xform - the specified AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform
hints - the specified RenderingHints sample code for java.awt.RenderingHints definition code for java.awt.RenderingHints
Returns:
a PaintContext that is used to generate a solid color pattern.
See Also:
Paint sample code for java.awt.Paint definition code for java.awt.Paint , PaintContext sample code for java.awt.PaintContext definition code for java.awt.PaintContext , Graphics2D.setPaint(java.awt.Paint) sample code for java.awt.Graphics2D.setPaint(java.awt.Paint) definition code for java.awt.Graphics2D.setPaint(java.awt.Paint)

getTransparency sample code for java.awt.Color.getTransparency() definition code for java.awt.Color.getTransparency()

public int getTransparency()
Returns the transparency mode for this Color. This is required to implement the Paint interface.

Specified by:
getTransparency sample code for java.awt.Transparency.getTransparency() definition code for java.awt.Transparency.getTransparency() in interface Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency
Returns:
this Color object's transparency mode.
See Also:
Paint sample code for java.awt.Paint definition code for java.awt.Paint , Transparency sample code for java.awt.Transparency definition code for java.awt.Transparency , createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) sample code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints) definition code for java.awt.Color.createContext(java.awt.image.ColorModel, java.awt.Rectangle, java.awt.geom.Rectangle2D, java.awt.geom.AffineTransform, java.awt.RenderingHints)