Ucigame - Gallery - FontDemo

Home | Getting Started | Reference | Introduction to Java | Gallery

Your browser cannot show Java applets. This program shows you the fonts that are installed on your computer. A complete list is displayed on the Java Console, and you can cycle through a display of each font by clicking on the game area.

FontDemo.java
import ucigame.*;

public class FontDemo extends Ucigame
{
    String[] fontList;
    int currFont = 0;

    public void setup()
    {
        // Show all available fonts in the command window or console.
        fontList = arrayOfAvailableFonts();
        for (String f : fontList)
            println(f);

        window.size(250, 250);
        window.title("FontDemo");
        framerate(20);
        canvas.background(255, 255, 200);
    }

    public void draw()
    {
        canvas.clear();

        canvas.font(fontList[currFont], PLAIN, 20);
        canvas.putText(fontList[currFont] + " PLAIN 20 A B C 1 2 3", 10, 20);
        canvas.font(fontList[currFont], BOLD, 20);
        canvas.putText(fontList[currFont] + " BOLD 20 A B C 1 2 3", 10, 50);
        canvas.font(fontList[currFont], ITALIC, 20);
        canvas.putText(fontList[currFont] + " ITALIC 20 A B C 1 2 3", 10, 80);
        canvas.font(fontList[currFont], BOLDITALIC, 20);
        canvas.putText(fontList[currFont] + " BOLDITALIC 20 A B C 1 2 3", 10, 110);
        canvas.font(fontList[currFont], PLAIN, 12);
        canvas.putText(fontList[currFont] + " PLAIN 12 A B C 1 2 3", 10, 140);
        canvas.font(fontList[currFont], BOLD, 12);
        canvas.putText(fontList[currFont] + " BOLD 12 A B C 1 2 3", 10, 170);
        canvas.font(fontList[currFont], ITALIC, 12);
        canvas.putText(fontList[currFont] + " ITALIC 12 A B C 1 2 3", 10, 200);
        canvas.font(fontList[currFont], BOLDITALIC, 12);
        canvas.putText(fontList[currFont] + " BOLDITALIC 12 A B C 1 2 3", 10, 230);
    }

    public void onMouseReleased()
    {
        currFont = currFont + 1;
        if (currFont >= fontList.length)
            currFont = 0;
    }

}