SimpleTest.java
/*
* Copyright © 2012 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);
hideOpenKeypadCommand();
}
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);
}
}
// The code block below is commented out because it does not compile on
// Java SDK 1.1 or earlier. However if compiled with Java SDK 2.0, the
// resulting JAR file can be run on pre-FT devices as well.
// Nokia User Interface 1.6 needs to be included in the project packages.
private void hideOpenKeypadCommand() {
/*
try {
String keyboardType = System.getProperty("com.nokia.keyboard.type");
if (keyboardType.equals("None")) {
// Full touch device detected
com.nokia.mid.ui.VirtualKeyboard.hideOpenKeypadCommand(true);
}
} catch (Exception e) {
// Do nothing
}
*/
}
}