Skip to content

Instantly share code, notes, and snippets.

@mkmozgawa

mkmozgawa/HelloWorld.java Secret

Created Oct 8, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.