說真的上一次裝 Wireless Toolkit 開發環境已經算是 2005 年了。老實說我還真的忘了該做什麼設定,就透過這次記錄一下吧!或許改天就要寫寫 Amazon Kindle 的相關程式
首先是下載 J2ME 開發的環境,接著則是設定 Eclipse 環境,流程:
- 安裝 Eclipse 和 JDK 開發環境
- Java SE Downloads - JDK 6 Update 18
- 由於 Wireless toolkit 是使用 32-bit 的環境,所以不能用 64-bit 囉
- Eclipse 3.5.1
- eclipse project downloads - http://download.eclipse.org/eclipse/downloads/
- Maintenance Build: 3.5.1 - Windows
- 下載 eclipse-SDK-3.5.1-win32.zip 並解壓縮完就算安裝好了
- Java SE Downloads - JDK 6 Update 18
- 下載與安裝 J2ME 環境
- Sun Java Wireless Toolkit for CLDC (formerly known as Java 2 Platform, Micro Edition (J2ME) Wireless Toolkit)
- 安裝過程會詢問你 JVM 位置,在此使用預設位置 C:\Program Files\Java\jdk1.6.0_18
- Sun Java Wireless Toolkit for CLDC (formerly known as Java 2 Platform, Micro Edition (J2ME) Wireless Toolkit)
- 增加相關 Eclipse Plugin
- [Help]->[Install New Software]
- Work with:http://eclipseme.org/updates
- 勾選 EclipseME 吧,在此測試版本是 1.7.9
- 版權什麼得就要同意一下,沒多久也就下載安裝好
- [Help]->[Install New Software]
- 設定 Eclipse
- [Window]->[Preferences]->[J2ME]->[Device Management]->[Import]
- Specify search directory
- C:\WTK2.5.2_01
- 打完若沒有動作,那就按一下 Refresh 就行
- Specify search directory
- [Window]->[Preferences]->[J2ME]->[Device Management]->[Import]
- 測試 J2ME
- [File]->[New]->[Project]->[J2ME]->[J2ME Midlet Suite]
- Project New:HelloWorld
- 接著點 Next 到 Finish 就行了
- 點選 Eclipse 左邊的 HelloWorld->src ,接著按右鍵 [New]->[Class]
- Name:HelloWorld
- 接著就把 HelloWorld.java 使用以下的程式碼覆蓋,程式來源:J2ME Eclipse - Setting up development environment with EclipseME
- import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet implements CommandListener {
private Command exitCommand;
private TextBox tbox;
public HelloWorld() {
exitCommand = new Command("Exit", Command.EXIT, 1);
tbox = new TextBox("Hello world MIDlet", "Hello World!", 25, 0);
tbox.addCommand(exitCommand);
tbox.setCommandListener(this);
}
protected void startApp() {
Display.getDisplay(this).setCurrent(tbox);
}
protected void pauseApp() {}
protected void destroyApp(boolean bool) {}
public void commandAction(Command cmd, Displayable disp) {
if (cmd == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
- import javax.microedition.midlet.*;
- 最後存檔完就可以按 Run 來看看
- [File]->[New]->[Project]->[J2ME]->[J2ME Midlet Suite]
沒有留言:
張貼留言