Actually my teacher gave this homework since Tuesday, but because I have lots of work to do such as go to library and find some books reference for my paper, so this homework have to wait.
I remember there's some saying that don't judge a book by it's cover, and don't judge my program by it's title. It says that simple program, but I need 2 hours to complete it. So, here is the code and you can try it. I hope this will help all of you that still learn about Java Mobile.
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author ACER
*/
public class Tgs extends MIDlet implements CommandListener {
Display display;
Form newsForm;
StringItem newsString;
Command exitCommand = new Command("Exit", Command.EXIT, 1);
Command whyCommand = new Command("Why", Command.OK, 1);
Command backCommand = new Command("Back", Command.BACK, 1);
Alert news;
public Tgs()
{
newsString = new StringItem("Hello Lois! ","Welcome to Java Mobile Programming");
newsForm = new Form("Hello World", new Item[] { newsString});
newsForm.addCommand(exitCommand);
newsForm.addCommand(whyCommand);
newsForm.setCommandListener(this);
news = new Alert("Hello World", "Because I'm cute!", null, AlertType.INFO);
news.setTimeout(Alert.FOREVER);
news.addCommand(backCommand);
}
public void startApp()
{
if (display == null)
{
display = Display.getDisplay(this);
}
display.setCurrent(newsForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d)
{
if (c == exitCommand)
{
destroyApp(true);
notifyDestroyed(); // Exit
}
if (c == whyCommand)
{
display.setCurrent(news, d);
}
}
}
And the result from that code look like this
 |
| Screenshot 1 |
 |
| Screenshot 2 |
 |
| Screenshot 3 |
EmoticonEmoticon