Java Reference
In-Depth Information
Display 18.22 Result of Running FontDisplay.java
Fonts may look somewhat different on your system.
the "SansSerif" font will not have these decorative little lines. As you might guess,
Monospaced ” means that all the characters have equal width.
Fonts can be given style modifiers, such as bold or italic, and they can come in dif-
ferent sizes. The second and third arguments to the constructor for Font specify the
style modifications and size for the font, as in the following, which occurs in the
actionPerformed method in Display 18.21:
new Font("Serif", Font.BOLD|Font.ITALIC, POINT_SIZE);
The second argument specifies style modifications. Note that you can specify multiple style
modifications by connecting them with the symbol | as in Font.BOLD|Font.ITALIC . 2 The
last argument specifies the size of the letters in the version of the font created.
Character sizes are specified in units known as points , so the size of a particular ver-
sion of a font is called a point size . One point is 1/72 of an inch, but measurements
of font sizes are not as precise as might be ideal; two different fonts of the same point
size may be slightly different in size.
The method setFont sets the font for the Graphics object, which is named g in
Display 18.21. The font remains in effect until it is changed. If you do not specify any
font, then a default font is used.
point size
2 The symbol | produces a “bitwise or of the numbers,” but that detail need not concern you. You
need not even know what is meant by a “bitwise or of the numbers.” Just think of | as a special way
to connect style specifications.
 
Search WWH ::




Custom Search