Hello World no Java ME
Dados do artigo
Artigo
Tradução:
Originado de Hello World in Java ME
Por TK2000
Última alteração feita por hamishwillee
em 16 Dec 2011
Se você deseja aprender uma nova linguage, o primeiro programa é o sempre e clássico "Heelo World!".
Este programa cria um novo form com um item string e um botão de sair (exit).
package helloworld;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class HelloWorldMidlet extends MIDlet implements CommandListener {
public HelloWorldMidlet() {
}
// Display (tela)
private Display display;
// Main form (form principal)
private Form form;
// For the message (para a mensagem)
private StringItem stringItem;
// For the exit command (para o comando de sair)
private Command exitCommand;
public void commandAction(Command command, Displayable displayable) {
if (displayable == form) {
if (command == exitCommand) {
exitMIDlet();
}
}
}
public void startApp() {
// Create form (cria o form)
stringItem = new StringItem( "Hello", "Hello World!");
form = new Form( null, new Item[] {stringItem});
exitCommand = new Command( "Exit", Command.EXIT, 1);
form.addCommand( exitCommand);
form.setCommandListener( this);
// Get display for drawning (pega a tela para desenhar)
display = Display.getDisplay(this);
display.setCurrent(form);
}
// Your MIDlet should not call pauseApp(),
// only system will call this life-cycle method
public void pauseApp() {
}
// Your MIDlet should not call destroyApp(),
// only system will call this life-cycle method
public void destroyApp(boolean unconditional) {
}
public void exitMIDlet() {
display.setCurrent(null);
notifyDestroyed();
}
}



(no comments yet)