The java.awt.Font and FontMetrics Class
Graphicsinstance.setFont(particularFont) will set the current Font in the instance Graphicsinstance of the Graphics class to the value particularFont of class Font.
- The default call setFont(particularFont) sets the Font in the current applet.
- setFont can also be used on instances of AWT components, as we shall see in later examples.
The class Font has an important constructor used as in
Font MyFont = new Font(”Serif", Font.PLAIN ,36);
- where one can use specific font names TimesRoman, Courier, Helvetica, ZapfDingbats, but Sun would prefer you use the generic names Serif, SansSerif, and MonoSpaced. Additional font names include Dialog (the default for many AWT components).
- Font.PLAIN, Font.BOLD, Font.ITALIC are possible text styles
In an applet, the font specified may not be available in a particular browser. To find out which fonts are available, one may call
- String fonts[] = Toolkit.getDefaultToolkit(). getFontList();