J2ME环境配置

Eclipse下J2ME配置



Eclipse版本:Release 3.5.2 英文版


1.安装 EclipseME(已经安装Eclipse的基本框架)

Help > Install New Software... 弹出对话框(图1)

Eclipse下J2ME配置图1

点击按钮“Add…”,弹出对话框并填入字符串(图2),点击按钮“OK”,即可更新安装。

Eclipse下J2ME配置
图2

2.Eclipse设备配置 (开发需要虚拟设备支持)

首先安装sun java wireless toolkit。

Windows > Preferences > J2ME > Device Management,如图3

Eclipse下J2ME配置图3

点击“Import…”,弹出对话框,如图4。点击“Browse…”,选择sun java wireless toolkit的安装目录 > 点击“Refresh” > 点击“Finish”。

Eclipse下J2ME配置
图4

3.Eclipse调试配置

Windows > Preferences > Java > Debug,如图5,保证框1中不被选中,一般推荐把框2时间改为至少15000。

Eclipse下J2ME配置
图5

4.Eclipse 混淆器配置 (打包用)

下载proguard4.4.zip包,解压即可。Windows > Preferences > J2ME >Packaging > Obfuscation,如图6,选择Proguard4.4的存放目录,点击“OK”即可。

Eclipse下J2ME配置
图6

5.新建J2ME Midlet Suite项目HelloWorldMidlet,编写第一个程序MyMIDlet,如表1

表1

//MyMIDlet.java

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener;

import javax.microedition.lcdui.Display;

import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Form;

import javax.microedition.midlet.MIDlet;

public class MyMIDlet extends MIDlet {

?????? private Form form;

?????? private final Command cmdExit = new Command("Exit",Command.EXIT,1);

?????? private char[] charArray = {

???????????????????? 'T','h','i','s',' ','i','s',' ',

???????????????????? 'm','y',' ','f','i','r','s','t',' ','J','2','M','E',' ',

???????????????????? 'p','r','o','g','r','a','m','.'};

?????? public MyMIDlet() {

????????????? // TODO Auto-generated constructor stub

????????????? form = new Form("Hello MyJ2ME");

?????????????

????????????? StringBuffer strBuf = new StringBuffer();

????????????? for(int i=0; i<charArray.length; i++)

????????????? {

???????????????????? strBuf.append(charArray[i]);

????????????? }

?????????????

????????????? form.append(strBuf.toString());

????????????? form.addCommand(cmdExit);

????????????? form.setCommandListener(new CommandListener(){

???????????????????? public void commandAction(Command arg0, Displayable arg1) {

??????????????????????????? // TODO Auto-generated method stub

??????????????????????????? if(cmdExit == arg0){

?????????????????????????????????? notifyDestroyed();

?????????????????????????????????? destroyApp(true);

??????????????????????????? }

???????????????????? }

????????????????????

????????????? });

?????? }

?????? protected void startApp(){

????????????? // TODO Auto-generated method stub

????????????? Display.getDisplay(this).setCurrent(form);

?????? }

?????? protected void pauseApp() {

????????????? // TODO Auto-generated method stub

?????? }

?????? protected void destroyApp(boolean arg0){

????????????? // TODO Auto-generated method stub

?????? }

6.打包生成手机可安装的文件

如图7操作,将在deployed文件夹生成可安装文件,把该文件夹中所有文件拷贝到手机中,手机中点击HelloWorldMidlet.jad即可将其安装。

Eclipse下J2ME配置

图7

标注:此过程中可能报错“…Could not find jar tool executable…”,解决方案:windows > preferences > java > installed jres,把已经安装的JRE的目录修改为jdk的安装目录。


你可能感兴趣的:(j2me)