Java Reference
In-Depth Information
Figur e 11•2. The standar d fonts and styles
Example 11•2: FontList.java (continued)
// Draw the applet.
public void paint(Graphics g) {
for(int f=0; f < families.length; f++) { // for each family
for(int s = 0; s < styles.length; s++) { // for each style
Font font = new Font(families[f],styles[s],18); // create font
g.setFont(font); // set font
String name = families[f] + " " +stylenames[s]; // create name
g.drawString(name, 20, (f*4 + s + 1) * 20);
// display name
}
}
}
}
Colors
A color in Java is represented by the
java.awt.Color
class. The
Color
class
defines a number of constants that refer to predefined
Color
objects for commonly
used colors, such as
Color.black
and
Color.white
. You can also create your own
custom
Color
object by specifying the red, green, and blue components of the
color. These components may be specified as integers between 0 and 255 or as
float
values between 0.0 and 1.0. Additionally, the static
getHSBColor()
method
allows you to create a
Color
object based on hue, saturation, and brightness val-
ues. As of Java 1.1, the
java.awt.SystemColor
subclass of
Color
defines a number
of constant
SystemColor
objects that represent standard colors in the system