Hello in J2ME

You might also like

You are on page 1of 2

package hello; import javax.microedition.midlet.*; import javax.microedition.lcdui.

*; // HelloMIDlet class which displays public class helloMIDlet extends MIDlet implements CommandListener { // define our variables // Form extends screen class and is used to forms and other GUIs Form form; /* * StringItem extends from Item and represents a string with a label and * text which can be appended to a displayable such as a Form */ StringItem text; /* * Command extends from Object and The Command class is a construct * that encapsulates the semantic information of an action. The behavior that * the command activates is not encapsulated in this object. This means that * command contains only information about "command" not the actual action * that happens when command is activated. The action is defined in a * CommandListener associated with the Displayable. */ Command exit; // Our explicit Constructor which gets called when a new application is created public helloMIDlet() { // Initialize our variables, they are self-explanatory

form = new Form("New Form"); text = new StringItem("", "Hello World of J2ME"); exit = new Command("Exit", Command.EXIT, 1); form.append(text); form.addCommand(exit); form.setCommandListener(this); } // The overridden method which gets called when exit command is selected public void commandAction(Command cmd, Displayable arg1) { // if this command is of EXIT type then call destroyApp method // and notify the application is destroyed if(cmd.getCommandType() == Command.EXIT) { destroyApp(false); notifyDestroyed(); } } // Method when application is started or resumed public void startApp() { // get Application Display Object and set form as current screen Display display = Display.getDisplay(this); display.setCurrent(form); } // Method called when app is paused public void pauseApp() {} // Method called when application is destroyed public void destroyApp(boolean unconditional) {} }

You might also like