DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
J2ME - HelloWorld
// Example Hello World Java MicroEdition
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class HelloJ2ME_a1 extends MIDlet
{
private Display mDisplay;
private Form mForm;
protected void startApp() throws MIDletStateChangeException
{
if(mForm == null)
{
// Creo il Form dove inserire il messaggio (questo puo' essere pensato come ad un JFrame)
mForm = new Form("Hello J2ME !!!");
// Ottengo un Display per la MIDlet
mDisplay = Display.getDisplay(this);
}
// Imposto il Form corrente nel Display
mDisplay.setCurrent(mForm);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
// Notifico alla JVM della morte della MIDlet (viene chiamato il Garbage Collector)
this.notifyDestroyed();
}
}




