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
<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
相关文章推荐
- JAVA游戏编程之三----j2me 手机游戏入门开发--俄罗斯方块_2
- JAVA游戏编程之三----j2me 手机游戏入门开发--俄罗斯方块_3_增加成绩记录
- JAVA游戏编程之二----j2me MIDlet 手机游戏入门开发--扫雷(3)-带线程--仿windows扫雷
- 用Eclipse开发J2ME手机游戏入门(环境安装)
- 用Eclipse开发J2ME手机游戏入门讲座
- 用Eclipse开发J2ME手机游戏入门(创建Hello)》
- JAVA游戏编程之二----j2me MIDlet 手机游戏入门开发--贪吃蛇
- JAVA游戏编程之三----j2me 手机游戏入门开发--俄罗斯方块_5_使用LUA脚本写游戏
- JAVA游戏编程之二----j2me MIDlet 手机游戏入门开发--扫雷(2)-不含线程
- 用Eclipse开发J2ME手机游戏入门讲座(续)
- JAVA游戏编程之三----j2me 手机游戏入门开发--俄罗斯方块_4_增加消除行声音
- JAVA游戏编程之二----j2me MIDlet 手机游戏入门开发 --扫雷(1)-不含线程
- JAVA游戏编程之二----j2me MIDlet 手机游戏入门开发--贪吃蛇_1
- 用Eclipse开发J2ME手机游戏入门讲座
- IPhone 手机开发平台入门介绍
- phonegap安卓手机开发入门
- 关于J2ME手机游戏开发的一些个人思考之起步篇
- Java手机开发平台 J2ME
- Google手机操作系统Android应用开发入门
- J2ME开发入门(二) 一个简单的分页