teapot4midlet.java

来自「一个J2ME Mobile 3D的培训教程」· Java 代码 · 共 78 行

JAVA
78
字号


import Teapot4Canvas;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class Teapot4MIDlet extends MIDlet implements CommandListener {

    // Holds the unique display
    private Display display = null;
    // Holds the canvas
    private Teapot4Canvas canvas = null;
    // Create exit command
    private Command exitCommand = new Command("Exit", Command.ITEM, 1);
    
    /**     * Teapot4MIDlet - default constructor.     */
    public Teapot4MIDlet() {
        super();
        // Create the display
        display = Display.getDisplay(this);
        // Create the canvas 
        canvas = new Teapot4Canvas(this);
        // Set the listener to be the MIDlet
        canvas.setCommandListener(this);
        // Add exit command to the canvas
        canvas.addCommand(exitCommand);
    }

    /**     * startApp()     */
    protected void startApp() throws MIDletStateChangeException {
        try {
            // Start canvas
            canvas.start();
            // Set canvas to the display
            display.setCurrent(canvas);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**     * pauseApp()     */
    protected void pauseApp() {
    }

   /**     * destroyApp()     */
    protected void destroyApp(boolean unconditional)
            throws MIDletStateChangeException {
        notifyDestroyed();
    }

    /**     * Handle commands.     */
    public void commandAction(Command cmd, Displayable disp) {
        if (cmd == exitCommand) {
            try {
                destroyApp(false);
                notifyDestroyed();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?