As you have read in the previous articles about the MIDlet life-cycle, startApp() is the method that is called by the J2ME runtime on the device and you can write your initializing code in this MIDlet method.
Following is a simple code chunk that will show a Form with a String on it.
How to create a Form in J2ME
In this code, on line 1 we create an instance of the Form. "Form Title" is obviously the text that will show as the title of the form on the screen. On line 2, we append a string to be shown on the form and the last line is making the Form visible on the screen.
Form f = new Form("Form Title");
f.append("Hello - This is the form");
Display.getDisplay(this).setCurrent(f);
Here is the full code MIDlet Example
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class FormExample extends MIDlet {
protected void startApp() throws MIDletStateChangeException {
Form f = new Form("Form Title");
f.append("Hello - This is the form");
Display.getDisplay(this).setCurrent(f);
}
public FormExample() {
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
}
Output of the above code:
Related Articles:
- J2ME Screens and User Interfaces
- J2ME - Alert - Code Example
- J2ME - Alert - How to show images in alerts
- J2ME - Alert - What are the alert types
No comments:
Post a Comment