Java Color Codes
Java programming language allows us to create different types of applications like windows application or web application. The user interface is an important factor while developing an application. The GUI of the Java application can be made interactive using different colors available in Java programming.
Java Color Constants
The color constants in Java are values that cannot be changed and can be used with different Java programs.
The following table shows the color constants available in the Java programming. The all-capital version depicts a constant value. But lowercase version also works fine.
Java Color Constants | |
---|---|
BLACK | black |
BLUE | blue |
CYAN | cyan |
DARK_GRAY | darkGray |
GRAY | gray |
GREEN | green |
LIGHT_GRAY | lightGray |
MAGENTA | magenta |
ORANGE | orange |
PINK | pink |
RED | red |
WHITE | white |
YELLOW | yellow |
Java Color Codes
The basic colors of color system are red, green, and blue. Java provides the Color class constructor with different RGB color codes as arguments. Many developer tools are available that helps in picking up the correct RGB value.
The following table shows some color code combinations using different RGB values.
Color | RGB value |
---|---|
Black | 0-0-0 |
Very light red | 255-102-102 |
Light red | 255-51-51 |
Red | 255-0-0 |
Dark red | 204-0-0 |
Very dark red | 153-0-0 |
Very light blue | 51-204-255 |
Light blue | 51-153-255 |
Blue | 0-0-255 |
Dark blue | 0-0-204 |
Very dark blue | 0-0-153 |
Very light green | 102-255-102 |
Light green | 0-255-51 |
Green | 0-204-0 |
Dark green | 0-153-0 |
Very dark green | 0-102-0 |
White | 255-255-255 |
Java AWT Color Class Program
Java Abstract Window Toolkit is an API for developing GUI based Java applications. Let’s create a Java program and use the Color class.
ColorExample.java
Output:
In the above code, an instance of a JPanel p is created. The Color class object c1 is created using the RGB values (0, 0, 204) passed as an argument to the constructor. The c1 color object is assigned as the background color for the JPanel p.
Java Color Constants Program
ColorConstExample.java
Output: