Class Color


  • public class Color
    extends java.lang.Object
    This class represents colors in the RGB color model.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      Compares this Color to the specified Color.
      int getBlueComponent()
      Returns the blue component of this color (as an integer between 0 and 255).
      int getGreenComponent()
      Returns the green component of this color (as an integer between 0 and 255).
      int getRedComponent()
      Returns the red component of this color (as an integer between 0 and 255).
      int hashCode()
      Returns a hash code for this Color.
      static Color of​(int red, int green, int blue)
      Creates the Color with the given RGB values.
      static Color of​(java.lang.String colorString)
      Creates the Color with the RGB values contained in the given color string.
      java.lang.String toString()
      Returns a string representation of this Color.
      • Methods inherited from class java.lang.Object

        clone, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • BLACK

        public static final Color BLACK
        The color black.
      • DARK_GRAY

        public static final Color DARK_GRAY
        The color dark gray.
      • LIGHT_GRAY

        public static final Color LIGHT_GRAY
        The color light gray.
      • WHITE

        public static final Color WHITE
        The color white.
      • RED

        public static final Color RED
        The color red.
      • GREEN

        public static final Color GREEN
        The color green.
      • BLUE

        public static final Color BLUE
        The color blue.
      • YELLOW

        public static final Color YELLOW
        The color yellow.
      • MAGENTA

        public static final Color MAGENTA
        The color magenta.
      • CYAN

        public static final Color CYAN
        The color cyan.
      • ORANGE

        public static final Color ORANGE
        The color orange.
    • Method Detail

      • of

        public static Color of​(int red,
                               int green,
                               int blue)
        Creates the Color with the given RGB values.
        Parameters:
        red - the value for the red component (must be between 0 and 255)
        green - the value for the green component (must be between 0 and 255)
        blue - the value for the blue component (must be between 0 and 255)
        Returns:
        the Color with the given RGB values
        Throws:
        java.lang.IllegalArgumentException - if any of the given values is outside the allowed range
      • of

        public static Color of​(java.lang.String colorString)
        Creates the Color with the RGB values contained in the given color string. The color string must be an "HTML color code", i.e. the RGB values must be formatted as hex triplets preceded with '#' (e.g. "#60DE60"). Hexadecimal values containing letters can be either uppercase or lowercase.
        Parameters:
        colorString - the RGB values formatted as hex triplets preceded with '#' (e.g. "#60DE60")
        Returns:
        the Color with the given RGB values
        Throws:
        java.lang.IllegalArgumentException - if colorString is null or not properly formatted
      • getRedComponent

        public int getRedComponent()
        Returns the red component of this color (as an integer between 0 and 255).
        Returns:
        the red component of this color (as an integer between 0 and 255)
      • getGreenComponent

        public int getGreenComponent()
        Returns the green component of this color (as an integer between 0 and 255).
        Returns:
        the green component of this color (as an integer between 0 and 255)
      • getBlueComponent

        public int getBlueComponent()
        Returns the blue component of this color (as an integer between 0 and 255).
        Returns:
        the blue component of this color (as an integer between 0 and 255)
      • toString

        public java.lang.String toString()
        Returns a string representation of this Color.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this Color
      • equals

        public boolean equals​(java.lang.Object o)
        Compares this Color to the specified Color.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the object to compare with
        Returns:
        true if the objects are the same; false otherwise
      • hashCode

        public int hashCode()
        Returns a hash code for this Color.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this Color