FontTest.java



import com.nttdocomo.ui.*;
public class FontTest extends IApplication {

    public FontCanvas canvas;
    public Font normal;
    public Font large;
    public Font small;
    public Font bold;
    public Font italic;
    public int width, height;
    public boolean paintFlag = true;

    public void start() {
        canvas = new FontCanvas();
        Display.setCurrent( canvas );
        canvas.setSoftLabel( Frame.SOFT_KEY_1, "Navy" );
        canvas.setSoftLabel( Frame.SOFT_KEY_2, "Aqua" );
        normal = Font.getDefaultFont();
        large = Font.getFont( Font.SIZE_LARGE );
        small = Font.getFont( Font.SIZE_SMALL );
        bold = Font.getFont( Font.STYLE_BOLD );
        italic = Font.getFont( Font.STYLE_ITALIC );
        width = Display.getWidth();
        height = Display.getHeight();
    }

    class FontCanvas extends Canvas {

        public void paint( Graphics g ) {

            String s = "tkww";
            int x=0;
            int y=0;
            int sw=0;

            if( paintFlag )
                g.setColor( g.getColorOfName( g.NAVY ) );
            else
                g.setColor( g.getColorOfName( g.AQUA ) );

            g.fillRect( 0, 0, width, height );

            if( paintFlag )
                g.setColor( g.getColorOfName( g.YELLOW ) );
            else
                g.setColor( g.getColorOfName( g.OLIVE ) );


            x = ( width - normal.stringWidth( s ) )/2;
            y += normal.getHeight() + 4;
            g.setFont( normal );
            g.drawString( s, x, y );

            x = ( width - large.stringWidth( s ) )/2;
            y += large.getHeight() + 4;
            g.setFont( large );
            g.drawString( s, x, y );

            x = ( width - small.stringWidth( s ) )/2;
            y += small.getHeight() + 4;
            g.setFont( small );
            g.drawString( s, x, y );

            x = ( width - bold.stringWidth( s ) )/2;
            y += bold.getHeight() + 4;
            g.setFont( bold );
            g.drawString( s, x, y );

            x = ( width - italic.stringWidth( s ) )/2;
            y += italic.getHeight() + 4;
            g.setFont( italic );
            g.drawString( s, x, y );
        }

        public void processEvent( int type, int param ) {
            if( type == Display.KEY_PRESSED_EVENT ) {
                if( param == Display.KEY_SOFT1 )
                    paintFlag = true;
                else if( param == Display.KEY_SOFT2 )
                    paintFlag = false;
             }
             repaint();
        }
    }
}