Skip to content

Instantly share code, notes, and snippets.

@mkmozgawa
Created October 8, 2020 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkmozgawa/b87d0d2125e924b4802ffdf1de578553 to your computer and use it in GitHub Desktop.
Save mkmozgawa/b87d0d2125e924b4802ffdf1de578553 to your computer and use it in GitHub Desktop.
A simple J2ME app
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet implements CommandListener {
private Display display;
private TextField field;
private String name;
private TextField greeting;
private Command writeName;
private Form form;
public HelloWorld() {
form = new Form("My first form");
field = new TextField("Tell me your name: ", "", 30, TextField.ANY);
form.append(field);
greeting = new TextField("", "Hello, person!", 30, TextField.UNEDITABLE);
form.append(greeting);
writeName = new Command("What's my name?", Command.OK, 0);
form.addCommand(writeName);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.OK) {
name = field.getString();
writeName(name);
}
}
private void writeName(String name) {
greeting.setString("Hello, " + name + "!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment