FileDocCategorySizeDatePackage
ImageMIDlet.javaAPI DocExample6077Sun Nov 04 15:44:48 GMT 2001ora.ch5

ImageMIDlet

public class ImageMIDlet extends javax.microedition.midlet.MIDlet implements javax.microedition.lcdui.CommandListener

Fields Summary
private javax.microedition.lcdui.Display
display
protected boolean
started
private javax.microedition.lcdui.Command
exitCommand
private javax.microedition.lcdui.Command
backCommand
private javax.microedition.lcdui.List
examplesList
private javax.microedition.lcdui.Canvas[]
canvases
private String[]
examples
Constructors Summary
Methods Summary
private voidaddCommands(javax.microedition.lcdui.Displayable d)

        d.addCommand(exitCommand);
        d.addCommand(backCommand);
        d.setCommandListener(this);
    
public voidcommandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)

        if (d == examplesList) {
            // New example selected
            int index = examplesList.getSelectedIndex();
            display.setCurrent(canvases[index]);
        } else if (c == exitCommand) {
            // Exit. No need to call destroyApp
            // because it is empty.
            notifyDestroyed();
        } else if (c == backCommand) {
            // Go back to main selection list
            display.setCurrent(examplesList);
        }
    
private voidcreateCanvases()

        canvases = new Canvas[examples.length];
        canvases[0] = createDrawImageCanvas();
        canvases[1] = createImageGraphicsCanvas();
    
private voidcreateCommands()

        exitCommand = new Command("Exit", Command.EXIT, 0);
        backCommand = new Command("Back", Command.BACK, 1);
    
private javax.microedition.lcdui.CanvascreateDrawImageCanvas()

        Canvas canvas = new DrawImageCanvas();        
        addCommands(canvas);
        return canvas;
    
private javax.microedition.lcdui.CanvascreateImageGraphicsCanvas()

        Canvas canvas = new ImageGraphicsCanvas();        
        addCommands(canvas);
        return canvas;
    
private voidcreateList()

        examplesList = new List("Select Example", List.IMPLICIT);
        for (int i = 0; i < examples.length; i++) {
            examplesList.append(examples[i], null);
        } 
        examplesList.setCommandListener(this);
    
protected voiddestroyApp(boolean unconditional)

    
protected voidpauseApp()

    
protected voidstartApp()


       
        if (!started) {
            started = true;
            display = Display.getDisplay(this);
            
            // Create the common commands
            createCommands();
            
            // Create the canvases
            createCanvases();
            
            // Create the list of examples
            createList();
            
            // Start with the List
            display.setCurrent(examplesList);
        }