FileDocCategorySizeDatePackage
DemoFonts.javaAPI DocExample2761Wed Aug 08 15:13:48 BST 2001None

DemoFonts

public class DemoFonts extends Object
A cache of the dynamically loaded fonts found in the fonts directory.

Fields Summary
private String[]
names
private static Hashtable
cache
Constructors Summary
public DemoFonts()



      
        cache = new Hashtable(names.length);
        for (int i = 0; i < names.length; i++) {
            cache.put(names[i], getFont(names[i]));
        }
    
Methods Summary
public static java.awt.FontgetFont(java.lang.String name)

        Font font = null;
        if (cache != null) {
            if ((font = (Font) cache.get(name)) != null) {
                return font;
            }
        }
        String fName = "fonts/" + name;
        try {
            InputStream is = ClassLoader.getSystemResourceAsStream(fName);
            font = Font.createFont(Font.TRUETYPE_FONT, is);
        } catch (Exception ex) { 
            ex.printStackTrace(); 
            System.err.println(fName + " not loaded.  Using serif font.");
            font = new Font("serif", Font.PLAIN, 24);
        }
        return font;