Picking Colors:

  1. Recall the Graphics object g passed into the paint(Graphics g) contains drawing information - including pen color.

  2. Recall also that you should cast the Graphics object g to a more advanced Graphics2D object g2.

  3. To set the the current pen color in Graphics2D object g2:

    g2.setColor(ColorObject)

    Java has a number of pre-defined Color objects for common colors:

    Example: picking color red
          g2.setColor(Color.red);
    

  4. Create your own color objects in Java:

  5. RGB values of some commonly used colors:

    Color RGB values
    Color.black 0.0F, 0.0F, 0.0F
    Color.red 1.0F, 0.0F, 0.0F
    Color.green 0.0F, 1.0F, 0.0F
    Color.blue 0.0F, 0.0F, 1.0F
    Color.white 1.0F, 1.0F, 1.0F
    Color.yellow 1.0F, 1.0F, 0.0F
    Color.pink 1.0F, 0.7F, 0.7F

  6. Documentation on java.awt.Color class: click here