home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.6 KB | 87 lines |
- import java.applet.Applet;
- import java.awt.*;
-
- /**
- * Class that determines which fonts are available
- */
- public class Fonts extends Applet {
-
- /*
- * Maximum number of fonts to display
- */
- final int MaxFonts = 10;
-
- /*
- * Width and height of bounding panel
- */
- int width, height;
-
- /*
- * Array of font names
- */
- String fontName[];
-
- /*
- * Array of fonts
- * Holds plain, italic, and bold for each font
- */
- Font theFonts[] = new Font[3 * MaxFonts];
-
- /*
- * The number of fonts found
- */
- int nfonts = 0;
-
- /*
- * Applet entry point
- */
- public void init () {
-
- int i;
- Dimension d = getSize ();
-
- width = d.width;
- height = d.height;
-
- theFonts[0] = new Font ("Courier", Font.PLAIN, 12);
- theFonts[1] = new Font ("System", Font.BOLD, 16);
- theFonts[2] = new Font ("Helvetica", Font.BOLD, 18);
- }
-
- /*
- * Draw the font names.
- * @param g - destination graphics object
- */
- public void paint (Graphics g) {
-
- int i;
-
-
- g.setFont (theFonts[0]);
- g.drawString ("Courier", 10, 30);
- g.setFont (theFonts[1]);
- g.drawString ("System", 70, 70);
- g.setFont (theFonts[2]);
- g.drawString ("Helvetica", 150, 90);
-
- }
-
- /*
- * Application entry point
- * Creates a window frame and adds the applet inside
- * @param args[] - command-line arguments
- */
- public static void main (String args[]) {
-
- Frame f = new Frame ("Fonts");
- Fonts fonts = new Fonts ();
-
- f.setSize (250, 200);
- f.add ("Center", fonts);
- f.show ();
- fonts.init ();
- }
- }
-
-
-