Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Java ME的Hello World

From Wiki
Jump to: navigation, search
WP Metro Icon Chinese.png
Article Metadata

文章
翻译:
User:Linux achi
最后由 hamishwillee 在 31 Jul 2013 编辑
假如我們想要學習一個新的語言,第一個程式總會是傳統的"Hello World!"

這一個程式會使用一個字串項目跟一個exit按鈕來建立一個新的表單。

要安裝Nokia設備所需要的開發工具,見文章開始使用Java ME安裝S60的Java ME開發工具使用MTJ建立第一支MIDlet

Helloworld.png


package com.example.helloworld;
 
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
 
public class HelloWorldMidlet extends MIDlet implements CommandListener {
 
public HelloWorldMidlet() {
}
// Display
private Display display;
// Main form
private Form form;
// For the message
private StringItem stringItem;
// For the exit command
private Command exitCommand;
 
public void commandAction(Command command, Displayable displayable) {
if (displayable == form) {
if (command == exitCommand) {
exitMIDlet();
}
}
}
 
public void startApp() {
// Create 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
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 31 July 2013, at 11:03.
239 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×