J2ME环境下开发HELLOWORLD程序全过程
1.系统要求
Pentium 100以上CPU
64MB 内存
Windows NT Workstation 4.0(Service Pack 3)或Windows 98
6MB自由硬盘空间
Java 2 SDK, Standard Version, 版本1.2.2或者更高
2.安装Java 2 SDK
在使用Motorola SDK之前必须安装JDK,Standard Edition。请从http://java.sun.com/products/jdk 下载JDK,并按照Sun的指导安装到PC中。
3.安装Motorola SDK
安装之前请先卸载以前版本的Motorola SDK:
1. 选择"开始à设置à控制板"
2. 选择"添加/删除程序"
3. 查找到"Motorola SDK Components for the J2ME Platform"
4. 点击"卸载"
5. 用资源管理器删除"\MotoSDK"目录
安装SDK:
1. 运行"Motorola_SDK.exe"
2. 按照提示安装程序
注意:安装程序需要口令,请向Motorola公司索取。
4.编写第一个程序
在目录"\MotoSDK\demo\midlets\com\mot\j2me\midlets\tutorials\"中,用编辑器创建文件"HelloWorld.java"。
/*
* HelloWorld.java
*
* June 27, 2000
*
* ? Copyright 2000 Motorola, Inc. All Rights Reserved.
* This notice does not imply publication.
*/
package com.mot.j2me.midlets.tutorials;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* A simple Hello World midlet
*
* @see MIDlet
*/
public class HelloWorld extends MIDlet {
/**
* Main application screen
*/
private Form mainScreen;
/**
* A reference to the Display
*/
private Display myDisplay;
/**
* Creates a screen for our midlet
*/
HelloWorld() {
myDisplay = Display.getDisplay(this);
mainScreen = new Form("Hello World");
/*
* Create a string item
*/
StringItem strItem = new StringItem("Hello", "This is a J2ME MIDlet.");
mainScreen.append(strItem);
}
/**
* Start the MIDlet
*/
public void startApp() throws MIDletStateChangeException {
myDisplay.setCurrent(mainScreen);
}
/**
* Pause the MIDlet
*/
public void pauseApp() {
}
J2ME开发步骤
/**
* Called by the framework before the application is unloaded
*/
public void destroyApp(boolean unconditional) {
}
}
5.编译
编译"HelloWord"
1.在命令行窗口中,进入目录"\MotoSDK\demo\midlets"
2.输入"compileAll com\mot\j2me\midlets\tutorials\HelloWorld.java"
6.运行
运行"HelloWord"
1.在命令行窗口中,进入目录"\MotoSDK\scripts"
2.输入"runEmul com.mot.j2me.midlets.tutorials.HelloWorld"