FileDocCategorySizeDatePackage
AnimationMIDlet.javaAPI DocExample9111Sun Nov 04 15:16:14 GMT 2001ora.ch5

AnimationMIDlet

public class AnimationMIDlet extends javax.microedition.midlet.MIDlet implements javax.microedition.lcdui.CommandListener, javax.microedition.lcdui.ItemStateListener

Fields Summary
private javax.microedition.lcdui.Display
display
protected boolean
started
private javax.microedition.lcdui.Command
exitCommand
private javax.microedition.lcdui.Command
setupCommand
private javax.microedition.lcdui.Command
runCommand
private javax.microedition.lcdui.Form
form
private AnimationCanvas
canvas
private javax.microedition.lcdui.Gauge
blockGauge
private javax.microedition.lcdui.Gauge
rateGauge
private static final int
FRAME_RATE
private static final int
BLOCK_COUNT
Constructors Summary
Methods Summary
public voidcommandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)

        if (c == exitCommand) {
            // Exit. No need to call destroyApp
            // because it is empty.
            notifyDestroyed();
        } else if (c == runCommand) {
            display.setCurrent(canvas);
        } else if (c == setupCommand) {
            display.setCurrent(form);
        }
    
protected ora.ch5.AnimationMIDlet$AnimationCanvascreateAnimationCanvas()

        return new AnimationCanvas();
    
protected voiddestroyApp(boolean unconditional)

    
public voiditemStateChanged(javax.microedition.lcdui.Item item)

        if (item == blockGauge) {
            int count = blockGauge.getValue();
            if (count < 1) {
                count = 1;
            }
            canvas.setBlockCount(count);
        } else if (item == rateGauge) {
            int count = rateGauge.getValue();
            if (count < 1) {
                count = 1;
            }
            canvas.setFrameRate(count);
        }            
    
protected voidpauseApp()

    
protected voidstartApp()

    
       
        if (!started) {
            display = Display.getDisplay(this);
            form = new Form("Animation");
            rateGauge = new Gauge("Frame rate", true, 10, FRAME_RATE);
            blockGauge = new Gauge("Blocks", true, 4, BLOCK_COUNT);
            form.append(rateGauge);
            form.append(blockGauge);
            form.setItemStateListener(this);
            
            canvas = createAnimationCanvas();            
            
            exitCommand = new Command("Exit", Command.EXIT, 0);
            setupCommand = new Command("Setup", Command.SCREEN, 0);
            runCommand = new Command("Run", Command.SCREEN, 0);
            
            canvas.addCommand(exitCommand);
            canvas.addCommand(setupCommand);
            form.addCommand(exitCommand);
            form.addCommand(runCommand);
            
            form.setCommandListener(this);
            canvas.setCommandListener(this);
            
            display.setCurrent(form);
            started = true;
        }