Java Reference
In-Depth Information
FIGURE 12-3
Output of the
FontsDisplayed
applet
class
Color
So far, we have used only the default colors in our GUI programs. For example, the text
always appeared as black. You may want to show the text in different colors or change
the background color of a component. Java provides the
class
Color
to accomplish this.
The
class
Color
is contained in the
package
java.awt
, so you need to use the
import
statement:
import
java.awt.*;
Table 12-5 shows various constructors and methods of the
class
Color
.
TABLE 12-5
Some Constructors and Methods of the
class
Color
Color(
int
r,
int
g,
int
b)
//Constructor
//Creates a Color object with the red value r, green value g,
//and blue value b. In this case, r, g, and b can be
//between 0 and 255.
//Example: new
Color(0, 255, 0)
//
creates a color with no red or blue component.
Color(
int
rgb)
//Constructor
//Creates a Color object with the red value r, green value g,
//and blue value b; RGB value consisting of the red component
//in bits 16-23, the green component in bits 8-15, and the
//blue component in bits 0-7.
//Example: new
Color(255)
//
creates a color with no red or green component.
Search WWH ::
Custom Search