FileDocCategorySizeDatePackage
FontTestlet.javaAPI DocJ2ME MIDP 2.04489Thu Nov 07 12:02:18 GMT 2002example.fonts

FontTestlet

public class FontTestlet extends javax.microedition.midlet.MIDlet implements javax.microedition.lcdui.CommandListener
FontTestlet is simple MIDlet which attempts to display text in all of the MIDP's different fonts.

Fields Summary
private javax.microedition.lcdui.Display
myDisplay
private FontCanvas
myCanvas
private int
currentFace
private javax.microedition.lcdui.Command
monospaceCommand
private javax.microedition.lcdui.Command
proportionalCommand
private javax.microedition.lcdui.Command
systemCommand
Constructors Summary
public FontTestlet()
FontTestlet - default constructor

  
             
      
	super();

	// Set up the user interface
	myDisplay = Display.getDisplay(this);
	myCanvas  = new FontCanvas(this);  // pointer to myself
	myCanvas.setCommandListener(this);
	myCanvas.addCommand(monospaceCommand);
	myCanvas.addCommand(proportionalCommand);
    
Methods Summary
public voidcommandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable disp)

	myCanvas.addCommand(getCurrentCommand());
	if (cmd == monospaceCommand) {
	    myCanvas.removeCommand(monospaceCommand);
	    currentFace = Font.FACE_MONOSPACE;
	} else if (cmd == proportionalCommand) {
	    myCanvas.removeCommand(proportionalCommand);
	    currentFace = Font.FACE_PROPORTIONAL;
	} else if (cmd == systemCommand) {
	    myCanvas.removeCommand(systemCommand);
	    currentFace = Font.FACE_SYSTEM;
	}

	myCanvas.repaint();
    
public voiddestroyApp(boolean cond)
destryApp() This is important. It closes the app's RecordStore

param
cond true if this is an unconditional destroy false if it is not currently ignored and treated as true

	myDisplay.setCurrent((Displayable)null);
	myCanvas.destroy();
    
javax.microedition.lcdui.CommandgetCurrentCommand()

	switch (currentFace) {
	case Font.FACE_MONOSPACE:
	    return monospaceCommand;
	case Font.FACE_PROPORTIONAL:
	    return proportionalCommand;
	case Font.FACE_SYSTEM:
	default:
	    return systemCommand;
	}
    
public voidinit()
initApp()

    
public voidpaint(javax.microedition.lcdui.Graphics g)
draw some stuff to the graphics context

	String title;
	int height = 0;

	g.setColor(0x00000000);
	g.fillRect(0, 0, myCanvas.getWidth(), myCanvas.getHeight());

	g.setColor(0x00ffffff);
	switch (currentFace) {
	case Font.FACE_SYSTEM:
	    title = "System";
	    break;
	case Font.FACE_PROPORTIONAL:
	    title = "Proportional";
	    break;
	case Font.FACE_MONOSPACE:
	    title = "Monospaced";
	    break;
	default:
	    title = "unknown";
	    break;
	}
	g.drawString(title, 0, 0, Graphics.TOP|Graphics.LEFT);
	height += g.getFont().getHeight();

	g.setFont(Font.getFont(currentFace, 
			       Font.STYLE_PLAIN, 
			       Font.SIZE_LARGE));
	g.drawString("Regular plain", 0, height, Graphics.TOP|Graphics.LEFT);
	height += g.getFont().getHeight();

	g.setFont(Font.getFont(currentFace, 
			       Font.STYLE_ITALIC, 
			       Font.SIZE_LARGE));
	g.drawString("Regular ital", 0, height, Graphics.TOP|Graphics.LEFT);
	height += g.getFont().getHeight();

	g.setFont(Font.getFont(currentFace, 
			       Font.STYLE_BOLD, 
			       Font.SIZE_LARGE));
	g.drawString("Bold plain", 0, height, Graphics.TOP|Graphics.LEFT);
	height += g.getFont().getHeight();

	g.setFont(Font.getFont(currentFace, 
			       Font.STYLE_BOLD|Font.STYLE_ITALIC, 
			       Font.SIZE_LARGE));
	g.drawString("Bold ital", 0, height, Graphics.TOP|Graphics.LEFT);
    
public voidpauseApp()
pauseApp()

	// System.out.println("pauseApp()");
    
public voidstartApp()
startApp()

	myDisplay.setCurrent(myCanvas);