J2ME HELLOWORLD 小试牛刀

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

T628降价了,买了一个玩玩,这个“鸡鸡”支持JAVA扩展,所以第一时间去http://developer.sonyericsson.com/site/global/home/p_home.jsp下载了最新的SDK(FILE SIZE:42M),下载的时候要注意,SDK说明中应该指出支持T628,eclipse和eclipseme是早就下好的,下面就该安装了:

1、安装j2se 1.4.2,并配置path和classpath

2、安装semc_j2me_sdk_2_1_5.exe,装完后我没有做任何配置(包括环境变量配置)

3、解压缩eclipse,然后把eclipseme解压缩到eclipse的plugins目录中

4、然后就配置eclipseme(如图1)

5、创建一个jeme工程,File/New/Project.../J2ME/J2ME Midlet Suite

6、在工程中添加Midlet,File/New/Other../J2ME/J2ME Midlet

7、编写代码

8、在Navigator的工程上点右键,执行右键菜单里的J2ME/Create Package

9、用模拟器(图2)或通过蓝牙传到手机上执行

(图1)

(图2)

代码如下:

----------------------------------------------------------

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.lcdui.StringItem;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

/*

* Created on 2005-1-10

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

/**

* @author libo

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

public class Helloworld extends MIDlet implements CommandListener{

private Display display;

private Form mainForm;

private StringItem stringItem;

private Command exitCommand=new Command("Exit",Command.EXIT ,1);

/**

*

*/

public Helloworld() {

super();

// TODO Auto-generated constructor stub

}

/* (non-Javadoc)

* @see javax.microedition.midlet.MIDlet#startApp()

*/

protected void startApp() throws MIDletStateChangeException {

// TODO Auto-generated method stub

initMIDlet();

display.setCurrent(mainForm);

}

private void initMIDlet(){

String text;

display=Display.getDisplay(this);

mainForm=new Form("关于");

stringItem=new StringItem(null,null);

text="这是我的第一个J2ME程序!";

stringItem.setText(text);

mainForm.append(stringItem);

mainForm.addCommand(exitCommand);

mainForm.setCommandListener(this);

}

/* (non-Javadoc)

* @see javax.microedition.midlet.MIDlet#pauseApp()

*/

protected void pauseApp() {

// TODO Auto-generated method stub

}

/* (non-Javadoc)

* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)

*/

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

// TODO Auto-generated method stub

System.out.println("exit the application");

}

public void commandAction(Command cmd,Displayable display){

if(cmd==exitCommand)

{

try{

destroyApp(false);

notifyDestroyed();

}catch(MIDletStateChangeException e){

e.printStackTrace();

}

}

}

}

-----------------------------------------

代码结束

提示:T628仅支持CLDC 1.0 和MIDP 1.0 ,在新建设工程时,平台选择Sony Ericsson J2ME SDK(WTK 1.0.4) Platform ,如果选择Sony Ericsson J2ME SDK(WTK 2.1) Platform 则,在模拟器上可以运行,但传到T628上会提示无效的应用程序。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航