×
Namespaces

Variants
Actions
Revision as of 02:17, 14 December 2013 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Hello World no Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

Artigo
Tradução:
Por TK2000
Última alteração feita por lpvalente em 14 Dec 2013

Se você deseja aprender uma nova linguagem, o primeiro programa é o sempre e clássico "Hello World!". Este artigo mostra um programa que cria um novo form com um item string e um botão de sair (exit).

Helloworld.png

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();
}
 
}
This page was last modified on 14 December 2013, at 02:17.
78 page views in the last 30 days.
×