Exercise 3: Color

Exercise 3: Color 2015-12-04T17:38:55+00:00

[ Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ]

In the last lesson, we used a number of colors predefined by Java: Color.red, Color.green, Color.magenta, etc. (for a complete list, go here). In this lesson, we learn how to create arbitrary colors, by specifying an RGB value. The example applets below generate spectrums of color and draw something with them.

The source code for the first applet:

(Download the below file: DrawingWithColor1.java)

The resulting applet:

 

A second example:

(Download the below file: DrawingWithColor2.java)

The output: