SimpleTest.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.
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class SimpleTest extends MIDlet implements CommandListener {
private HelloCanvas myCanvas;
private Form myForm;
private Gauge myGauge;
private TextField textField;
private Command backCommand = new Command("Back", Command.BACK, 1);
private Command messageCommand = new Command("Message", Command.SCREEN, 1);
private Command displayCommand = new Command("Display Message", Command.SCREEN, 1);
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command showCommand = new Command("Show Levels", Command.SCREEN, 1);
public SimpleTest() {
myCanvas = new HelloCanvas();
myCanvas.addCommand(backCommand);
myCanvas.addCommand(messageCommand);
myForm = new Form("Gauge level");
myGauge = new Gauge("Value", true, 120, 10);
textField = new TextField("Enter number", "", 3, TextField.NUMERIC);
myForm.append(myGauge);
myForm.append(textField);
myForm.addCommand(showCommand);
myForm.addCommand(displayCommand);
myForm.addCommand(exitCommand);
myCanvas.setCommandListener(this);
myForm.setCommandListener(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(myForm);
}
public void pauseApp() {
}
public void destroyApp(boolean a) throws MIDletStateChangeException {
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
notifyDestroyed();
}
if (c == messageCommand) {
myCanvas.newMessage();
}
if (c == backCommand) {
Display.getDisplay(this).setCurrent(myForm);
}
if (c == displayCommand) {
Display.getDisplay(this).setCurrent(myCanvas);
}
if (c == showCommand) {
String valueString = textField.getString();
int value = 0;
if (!valueString.equals("")) {
value = Integer.parseInt(valueString);
}
myGauge.setValue(value);
}
}
}