Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Color Class (from awt)

 

 

Introduction

 

Colors for drawing are selected by using the java setColor method. These are the predefined colors.
 

    Color.black 

    Color.blue

    Color.cyan

    Color.darkGray

    Color.gray

    Color.green

    Color.red

    Color.white

    Color.yellow

 

Usage


    g.setColor(Color.red);
    g.setColor(Color.green);
    g.setColor(Color.yellow);
    etc..

 

Java Custom Colors

 

If you want to create your own custom color, then you can use the Color constructor that takes red, green , and blue parameters as illustrated below.


    Color( redLevel, greenLevel, blueLevel);
    The three levels are on a scale from 0 to 255.
    Color(255,0,0) is red ;
    Color(0,255,0) is green ;
    Color(0,0,255) is blue ;
    etc.


To use a custom color, write code like the following.


Color c = new Color(150, 250, 150);
g.setColor(c);