FileDocCategorySizeDatePackage
AllFonts.javaAPI DocExample5612Wed Aug 08 15:13:48 BST 2001demos.Fonts

AllFonts

public class AllFonts extends AnimatingControlsSurface
Scrolling text of fonts returned from GraphicsEnvironment.getAllFonts().

Fields Summary
private static Vector
fonts
private int
nStrs
private int
strH
private int
fi
protected int
fsize
protected Vector
v
Constructors Summary
public AllFonts()



      
        setBackground(Color.white);
        setSleepAmount(500);
        setControls(new Component[] { new DemoControls(this) });
    
Methods Summary
public voidhandleThread(int state)

 
public static voidmain(java.lang.String[] argv)

        createDemoFrame(new AllFonts());
    
public voidrender(int w, int h, java.awt.Graphics2D g2)


        g2.setColor(Color.black);

        int yy = (fi >= fonts.size()) ? 0 : h - v.size() * strH - strH/2;

        for (int i = 0; i < v.size(); i++) {
            Font f = (Font) v.get(i);
            int sw = getFontMetrics(f).stringWidth(f.getName());
            g2.setFont(f);
            g2.drawString(f.getName(), (int) (w/2-sw/2),yy += strH);
        }
    
public voidreset(int w, int h)

        v.clear();
        Font f = ((Font) fonts.get(0)).deriveFont(Font.PLAIN,fsize);
        FontMetrics fm = getFontMetrics(f);
        strH = (int) (fm.getAscent()+fm.getDescent());
        nStrs = h/strH + 1;
        fi = 0;
    
public voidstep(int w, int h)

        if (fi < fonts.size()) {
            v.addElement(((Font) fonts.get(fi)).deriveFont(Font.PLAIN,fsize));
        }
        if (v.size() == nStrs && v.size() != 0 || fi > fonts.size()) {
            v.removeElementAt(0);
        }
        fi = (v.size() == 0) ? 0 : ++fi;