j2me手机开发入门

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
 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值