Class Color


  • public class Color
    extends java.lang.Object
    Color represented in RGB format.
    See Also:
    Colors RGB.
    • Field Detail

      • WHITE

        public static final Color WHITE
      • SILVER

        public static final Color SILVER
      • GRAY

        public static final Color GRAY
      • BLACK

        public static final Color BLACK
      • RED

        public static final Color RED
      • MAROON

        public static final Color MAROON
      • YELLOW

        public static final Color YELLOW
      • OLIVE

        public static final Color OLIVE
      • LIME

        public static final Color LIME
      • GREEN

        public static final Color GREEN
      • CYAN

        public static final Color CYAN
      • TEAL

        public static final Color TEAL
      • BLUE

        public static final Color BLUE
      • NAVY

        public static final Color NAVY
      • FUCHSIA

        public static final Color FUCHSIA
      • PURPLE

        public static final Color PURPLE
      • ORANGE

        public static final Color ORANGE
    • Constructor Detail

      • Color

        public Color​(int red,
                     int green,
                     int blue)
        Creates a Color from RGB values.
        Parameters:
        red - is the red color component of the RGB color in the range [0 - 255]
        green - is the green color component of the RGB color in the range [0 - 255]
        blue - is the red blue component of the RGB color in the range [0 - 255]
        See Also:
        Colors RGB.
    • Method Detail

      • getRed

        public int getRed()
        Returns the red color component of the color.
        Returns:
        the red color component of the RGB color in the range [0 - 255]
      • getGreen

        public int getGreen()
        Returns the green color component of the color.
        Returns:
        the green color component of the RGB color in the range [0 - 255]
      • getBlue

        public int getBlue()
        Returns the blue color component of the color.
        Returns:
        the blue color component of the RGB color in the range [0 - 255]
      • toHex

        public java.lang.String toHex()
        Returns the color as a hex triplet of six hexadecimal digits representing an RGB color, e.g. "0099CC".
        Returns:
        the color as a hex triplet of six hexadecimal digits representing an RGB color, e.g. "0099CC".
      • fromString

        public static Color fromString​(java.lang.String str)
        Creates a color from a string. Currently, only numeric RGB values are supported. This method works the same was as fromHex(java.lang.String) except that is required as hash sign before the hex value. An example of a numeric RGB value is "#09C" or "#0099CC", which both represents the same color.
        Parameters:
        str - is a string containing either a three or six hexadecimal RGB values like "#09C" or "#0099CC".
        Returns:
        the created Color; null if the input parameter is null.
        See Also:
        Colors RGB, Web Colors
      • fromHex

        public static Color fromHex​(java.lang.String hexTriplet)
        Creates a color from a hex triplet. A hex triplet is either three or six hexadecimal digits that represents an RGB Color.
        An example of a hex triplet is "09C" or "0099CC", which both represents the same color.
        Parameters:
        hexTriplet - is a string containing either a three or six hexadecimal numbers like "09C" or "0099CC".
        Returns:
        the created Color.
        See Also:
        Colors RGB, Web Colors
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object