您的位置:首页 > 其它

j2me手机开发入门

2007-08-24 15:26 351 查看
j2me手机开发入门

<1> 下载 eclipse3.2 /
j2me_wireless_toolkit-2_1_01-windows.exe
/ eclipseme1.6.8并安装
//使用eclipse3.1有点问题

<2>重新启动eclipse,点击 windows ->选择 preference ->选择 j2me ->选择 Device Managment ->点击import ->

选择 Browes ->选择 jwtk2.2的安装目录->点击 Refresh-->finish.





<3>开启测试项目 ,重新启动eclipse,file ->new ->project ->j2me ->j2me midlet suite ->命名项目名称为

testj2me



<4>验证环境搭建,在项目中编写一个名为HelloWorld 的java程序,源码如下:

import java.util.Date;

import javax.microedition.lcdui.Alert;
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.TextBox;
import javax.microedition.midlet.MIDlet;

public class HelloWorld extends MIDlet implements CommandListener{
private TextBox textbox;
protected Alert timeAlert;
protected Form form;
/**
* Constructor of the HelloWorld class
*/
public HelloWorld() {
textbox = new TextBox("", "Hello World!", 20, 0);
timeAlert = new Alert("Alert!");
timeAlert.setString(new Date().toString());
timeAlert.setTimeout(Alert.FOREVER);

}
/*
* The startApp method is used for starting or restarting a MIDlet.
*
* @see javax.microedition.midlet.MIDlet#startApp()
*/
public void startApp() {
// Display.getDisplay(this).setCurrent(form);
// Form f = new Form("HelloTest");
Display.getDisplay(this).setCurrent(timeAlert);
}
/*
* The pauseApp method is called by the system to ask a MIDlet to "pause"
*
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
public void pauseApp() {
}
/*
* The destroyApp method is called by the system when the MIDlet is about to
* be destroyed
*
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
public void destroyApp(boolean unconditional) {
form=null;
}
public void commandAction(Command c, Displayable d)
{
if(c.getCommandType()==(Command.EXIT)){
// Destroy this MIDlet
destroyApp(true);
// Notify the application management software that this MIDlet
// has entered the destroyed state
notifyDestroyed();
}else{
submit(); // if submit ,excute submit() method;
}

}
private void submit(){
timeAlert = new Alert("Alert!");
timeAlert.setString("Submit success!");
Display.getDisplay(this).setCurrent(timeAlert);
}
}

<5>运行 -> 选择run as -> emulated j2me midlet.
参考网站:http://www.j2medev.com/Index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: