Sunday, February 18, 2007

Example Code : Hello World!

As you guess, our first mobile program is HelloWorld which simply say HelloWorld lol

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

/**
*
* @author sezera.blogspot.com
* @version 0000
*/
public class HelloPhone extends MIDlet implements CommandListener{
private Form helloForm;
private Command okCommand;
private StringItem msgStringItem;

public void startApp() {
getDisplay().setCurrent(get_helloForm());
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command,Displayable displayable)
{
if(displayable == helloForm){
if(command == okCommand){
//exit Midlet
getDisplay().setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
}
}
public Form get_helloForm()
{
if(helloForm == null){
helloForm = new Form(null,new Item[]{get_helloStringItem()});
helloForm.addCommand(get_okCommand());
helloForm.setCommandListener(this);
}
return helloForm;
}
public Display getDisplay()
{
return Display.getDisplay(this);
}
public StringItem get_helloStringItem() {
if (msgStringItem == null) {
msgStringItem = new StringItem(null,"Hello World!");
}
return msgStringItem;
}
public Command get_okCommand() {
if (okCommand == null) {
okCommand = new Command("Okey", Command.OK,1);
}
return okCommand;
}

}

No comments: