Class Color
java.lang.Object
Color
Immutable class representing a computer displayable color. Colors are
represented using the hexadecimal, rgb, and cmyk methods.
Class-defined colors match CSS usage.
Class-defined colors match CSS usage.
-
Field Summary
Modifier and TypeFieldDescriptionint
The amount of Blue in the color (a value between 0 and 255) Using RGB representation.static Color
Constant representation of CSS-compatible Black.static Color
Constant representation of CSS-compatible Blue.static Color
Constant representation of CSS-compatible Brown.double
The amount of Cyan in the color (a value between 0 and 255) using CMYK representation.int
The amount of Green in the color (a value between 0 and 255) Using RGB representation.static Color
Constant representation of CSS-compatible Green.int
The hex-code representation of the color.double
The CMYK Key value of the color.double
The amount of Magenta in the color (a value between 0 and 255) using CMYK representation.static Color
Constant representation of CSS-compatible Orange.static Color
Constant representation of CSS-compatible Purple.int
The amount of Red in the color (a value between 0 and 255).static Color
Constant representation of CSS-compatible Red.static Color
Constant representation of CSS-compatible White.double
The amount of Yello in the color (a value between 0 and 255) using CMYK representation.static Color
Constant representation of CSS-compatible Yellow. -
Constructor Summary
-
Method Summary
-
Field Details
-
r
public final int rThe amount of Red in the color (a value between 0 and 255). Using RGB representation. -
g
public final int gThe amount of Green in the color (a value between 0 and 255) Using RGB representation. -
b
public final int bThe amount of Blue in the color (a value between 0 and 255) Using RGB representation. -
c
public final double cThe amount of Cyan in the color (a value between 0 and 255) using CMYK representation. -
m
public final double mThe amount of Magenta in the color (a value between 0 and 255) using CMYK representation. -
y
public final double yThe amount of Yello in the color (a value between 0 and 255) using CMYK representation. -
k
public final double kThe CMYK Key value of the color. -
hex
public final int hexThe hex-code representation of the color. -
RED
Constant representation of CSS-compatible Red. -
GREEN
Constant representation of CSS-compatible Green. -
BLUE
Constant representation of CSS-compatible Blue. -
BROWN
Constant representation of CSS-compatible Brown. -
ORANGE
Constant representation of CSS-compatible Orange. -
PURPLE
Constant representation of CSS-compatible Purple. -
YELLOW
Constant representation of CSS-compatible Yellow. -
BLACK
Constant representation of CSS-compatible Black. -
WHITE
Constant representation of CSS-compatible White.
-
-
Constructor Details
-
Color
public Color()No args constructor. Defaults to black. -
Color
Constructs a color of given r, g, and b values.- Parameters:
r
- the quantity of red in the color (range from 0 to 255)g
- the quantity of green in the color (range from 0 to 255)b
- the quantity of blue in the color (range from 0 to 255)- Throws:
IllegalArgumentException
-
Color
public Color(double c, double m, double y, double k)Constructs a color of a given CMYK value.- Parameters:
c
- amount of Cyan in the color (range from 0 to 1)m
- amount of Magenta in the color (range from 0 to 1)y
- amount of Yello in the color (range from 0 to 1)k
- amount of black (key value) in the color (range from 0 to 1)
-
-
Method Details
-
mix
Gives the color midway between two colors as its "mixture." Mixed color is the average of the rgb values of the two colors.- Parameters:
x
- a color to mixy
- a second color to mix with x- Returns:
- a color with the average rgb values of x and y.
-
mix
Gives the color between x and y with a given weight/ratio applied to x. Higherratio
values imply greater weight towards and lower values a higher weight towards y.- Parameters:
x
- a color to mixy
- a second color to mix with xratio
- the proportion of x in the final mixture- Returns:
- a
Color
equivalent to the mixture of x and y with the given weight applied to x.
-