Java Lab Documentation

Color

Category:org.code.media

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

TypeNameDescription
static final intMAX_VALUE = 255

the maximum value for the red, green, and blue values of this Color

Color.MAX_VALUE
static final intMIN_VALUE = 0

the minimum value for the red, green, and blue values of this Color

Color.MIN_VALUE
final intred

the red value of this Color

final intgreen

the green value of this Color

final intblue

the blue value of this Color

static final Color WHITE

   a color with the value (255, 255, 255)

Color.WHITE
static final Color SILVER

   a color with the value (192, 192, 192)

Color.SILVER
static final Color GRAY

   a color with the value (128, 128, 128)

Color.GRAY
static final Color BLACK

   a color with the value (0, 0, 0)

Color.BLACK
static final ColorRED

   a color with the value (255, 0, 0)

Color.RED
static final ColorMAROON

   a color with the value (128, 0, 0)

Color.MAROON
static final Color YELLOW

   a color with the value (255, 255, 0)

Color.YELLOW
static final Color OLIVE

   a color with the value (128, 128, 0)

Color.OLIVE
static final Color LIME

   a color with the value (0, 255, 0)

Color.LIME
static final Color GREEN

   a color with the value (0, 128, 0)

Color.GREEN
static final Color AQUA

   a color with the value (0, 255, 255)

Color.AQUA
static final Color TEAL

   a color with the value (0, 128, 128)

Color.TEAL
static final Color BLUE

   a color with the value (0, 0, 255)

Color.BLUE
static final Color NAVY

   a color with the value (0, 0, 128)

Color.NAVY
static final Color FUCHSIA

   a color with the value (255, 0, 255)

Color.FUCHSIA  
static final Color PURPLE

   a color with the value (128, 0, 128)

Color.PURPLE
static final Color PINK

   a color with the value (255, 192, 203)

Color.PINK
static final Color ORANGE

   a color with the value (255, 165, 0)

Color.ORANGE
static final Color GOLD

   a color with the value (255, 215, 0)

Color.GOLD
static final Color BROWN

   a color with the value (165, 42, 42)

Color.BROWN
static final Color CHOCOLATE

   a color with the value (210, 105, 30)

Color.CHOCOLATE
static final Color TAN

   a color with the value (210, 180, 140)

Color.TAN
static final Color TURQUOISE

   a color with the value (64, 224, 208)

Color.TURQUOISE
static final Color INDIGO

   a color with the value (75, 0, 130)

Color.INDIGO
static final Color VIOLET

   a color with the value (238, 130, 238)

Color.VIOLET
static final Color BEIGE

   a color with the value (245, 245, 220)

Color.BEIGE
static final Color IVORY

   a color with the value (255, 255, 240)

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

NameTypeRequired?Description
colorString

the name of the color (case-insensitive)

Examples

Possible color names are:

Color myColor = new Color("navy");
Overloads

Color

public Color(int red, int green, int blue)

Create a new Color object based on the red, green, and blue values provided.

Parameters

NameTypeRequired?Description
redint

the red value to set the Color (between 0 and 255)

greenint

the green value to set the Color (between 0 and 255)

blueint

the blue value to set the Color (between 0 and 255)

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

NameTypeRequired?Description
colorColor

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