FileDocCategorySizeDatePackage
GraphicsMIDlet.javaAPI DocExample10640Sun Nov 04 15:16:42 GMT 2001ora.ch5

GraphicsMIDlet

public class GraphicsMIDlet 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 javax.microedition.lcdui.CanvascreateArcsCanvas()

        Canvas canvas = new ArcsCanvas();        
        addCommands(canvas);
        return canvas;
    
private voidcreateCanvases()

        canvases = new Canvas[examples.length];
        canvases[0] = createLinesCanvas();
        canvases[1] = createRectanglesCanvas();
        canvases[2] = createRectangleFillsCanvas();
        canvases[3] = createArcsCanvas();
        canvases[4] = createFilledArcsCanvas();
        canvases[5] = createTextCanvas();
        
    
private voidcreateCommands()

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

        Canvas canvas = new FilledArcsCanvas();        
        addCommands(canvas);
        return canvas;
    
private javax.microedition.lcdui.CanvascreateLinesCanvas()

        Canvas canvas = new LineCanvas();        
        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);
    
private javax.microedition.lcdui.CanvascreateRectangleFillsCanvas()

        Canvas canvas = new RectangleFillsCanvas();        
        addCommands(canvas);
        return canvas;
    
private javax.microedition.lcdui.CanvascreateRectanglesCanvas()

        Canvas canvas = new RectanglesCanvas();        
        addCommands(canvas);
        return canvas;
    
private javax.microedition.lcdui.CanvascreateTextCanvas()

        Canvas canvas = new TextCanvas();        
        addCommands(canvas);
        return canvas;
    
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);
        }