-
-
Save mkmozgawa/b87d0d2125e924b4802ffdf1de578553 to your computer and use it in GitHub Desktop.
A simple J2ME app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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