AMMSMIDlet.java
/*
* Copyright © 2011 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.midp.examples.jsr234.mansion;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* AMMSMIDlet class.
*
*/
public class AMMSMIDlet extends MIDlet implements CommandListener {
Display display;
MansionCanvas canvas;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command backCommand = new Command("Back", Command.SCREEN, 1);
private Command helpCommand = new Command("Help", Command.HELP, 1);
private Form helpScreen;
/*
* Create the canvas
*/
public AMMSMIDlet() {
display = Display.getDisplay(this);
canvas = new MansionCanvas(display);
canvas.addCommand(exitCommand);
canvas.addCommand(helpCommand);
canvas.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
canvas.start();
}
public void pauseApp() {
canvas.pause();
}
public void destroyApp(boolean unconditional) throws MIDletStateChangeException {
canvas.destroy();
}
/*
* Respond to a command issued on the Canvas.
*/
public void commandAction(Command c, Displayable s) {
if (c == backCommand) {
canvas.start();
} else if (c == helpCommand) {
canvas.pause();
showHelp();
} else if (c == exitCommand) {
try {
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException ex) {
}
}
}
/*
* Put up the help screen. Create it if necessary.
* Add only the Resume command.
*/
void showHelp() {
if (helpScreen == null) {
helpScreen = new Form("Walking Help");
helpScreen.append("^ = walk forward\n");
helpScreen.append("v = walk backwards\n");
helpScreen.append("< = turn left\n");
helpScreen.append("> = turn right\n");
helpScreen.append("fire = change reverb manually\n");
}
helpScreen.addCommand(backCommand);
helpScreen.setCommandListener(this);
display.setCurrent(helpScreen);
}
}