Java Reference
In-Depth Information
8
panel.setBackground(Color.YELLOW);
9
10
Graphics g = panel.getGraphics();
11
for ( int i = 0; i < 10; i++) {
12
g.drawString("There is no place like home",
13
i * 5, 10 + i * 10);
14
}
15
}
16 }
This program produces the output shown in Figure 3G.10.
Figure 3G.10
Output of DrawStringMessage
Fonts are used to describe different styles for writing characters on the screen. If
you'd like to change the style or size of the onscreen text, you can use the setFont
method of the Graphics object.
Font
An overall design for a set of text characters, including the style, size,
weight, and appearance of each character.
This method changes the text size and style in which strings are drawn.
The parameter to setFont is a Font object. A Font object is constructed by pass-
ing three parameters—the font's name as a String , its style (such as bold or italic),
and its size as an integer:
new Font(<name>, <style>, <size>)
Common font styles such as bold are implemented as constants in the Font class.
The available constants and some popular font names are listed in Tables 3G.4
and 3G.5.
 
Search WWH ::




Custom Search