Color
Represents a color as amounts of red, green, and blue (ranging from 0
to 255
) that blend together to make a unique color. This class also provides a number of preset colors, like fuschia
, which can be referenced either by a string value or as one of the constants in this class, e.g. Color.FUSCHIA
.
Fields
Type | Name | Description |
---|---|---|
static final int | MAX_VALUE = 255 | the maximum value for the red, green, and blue values of this
|
static final int | MIN_VALUE = 0 | the minimum value for the red, green, and blue values of this
|
final int | red | the red value of this |
final int | green | the green value of this |
final int | blue | the blue value of this |
static final Color | WHITE |
|
static final Color | SILVER |
|
static final Color | GRAY |
|
static final Color | BLACK |
|
static final Color | RED |
|
static final Color | MAROON |
|
static final Color | YELLOW |
|
static final Color | OLIVE |
|
static final Color | LIME |
|
static final Color | GREEN |
|
static final Color | AQUA |
|
static final Color | TEAL |
|
static final Color | BLUE |
|
static final Color | NAVY |
|
static final Color | FUCHSIA |
|
static final Color | PURPLE |
|
static final Color | PINK |
|
static final Color | ORANGE |
|
static final Color | GOLD |
|
static final Color | BROWN |
|
static final Color | CHOCOLATE |
|
static final Color | TAN |
|
static final Color | TURQUOISE |
|
static final Color | INDIGO |
|
static final Color | VIOLET |
|
static final Color | BEIGE |
|
static final Color | IVORY |
|
Method Details
Color
public Color(String color) throws IllegalArgumentException
Creates a Color
object from a String
, like "red"
or "brown"
. If the name is not recognized, this constructor will throw an IllegalArgumentException
.
Parameters
Name | Type | Description |
---|---|---|
color | String | the name of the color (case-insensitive) |
Examples
Possible color names are:
Color myColor = new Color("navy");
Color
public Color(int red, int green, int blue)
Create a new Color
object based on the red, green, and blue values provided.
Parameters
Name | Type | Description |
---|---|---|
red | int | the red value to set the |
green | int | the green value to set the |
blue | int | the blue value to set the |
Examples
Color myColor = new Color(251, 139, 36);
Color
public Color(Color color)
Creates a new Color
object by copying the red, green, and blue values from the specified Color
.
Parameters
Name | Type | Description |
---|---|---|
color | Color | the color to copy |
Examples
Color firstColor = new Color(251, 139, 36);
Color secondColor = new Color(firstColor);
getRed
public int getRed()
Returns the amount of red of this Color
(ranging from 0
to 255
).
Examples
Color myColor = new Color(251, 139, 36);
int redValue = myColor.getRed();
System.out.println("The red value of myColor is " + redValue);
Output:
The red value of myColor is 251
getGreen
public int getGreen()
Returns the amount of green of this Color
(ranging from 0
to 255
).
Examples
Color myColor = new Color(251, 139, 36);
int greenValue = myColor.getGreen();
System.out.println("The red value of myColor is " + greenValue);
Output:
The red value of myColor is 139
getBlue
public int getBlue()
Returns the amount of blue of this Color
(ranging from 0
to 255
).
Examples
Color myColor = new Color(251, 139, 36);
int blueValue = myColor.getBlue();
System.out.println("The red value of myColor is " + blueValue);
Output:
The red value of myColor is 36