上一篇:增强J2ME的String能力——分割字符串(附源代码) >>
Pass J2ME (1) - MIDP State
pauseApp()
destroyApp()
startApp()
重写这三个方法。AM将会在相应的时间调用。
而
notifyDestroyed()
notifyPaused()
resumeRequest()
则是让你有机会去通知AM需要做什么。
下面是一个简单的例子,可以根据自己扩充测试一下。有一点比较奇怪的就是,理论上说,在Midlet处于Active状态的时候,如果有电话进入,AM会调用pauseApp()。但是实际测试时,没有发现AM调用这个方法。
package net.csdn.blog.vincint;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* This is a simple test to help me understanding the Midlet state
*
* <p>Title: Midlet Test</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: http://blog.csdn.net/Vincint</p>
* @author Vincint
* @version 1.0
*/
public class MidletState
extends MIDlet
implements
CommandListener {
protected Form form;
protected Command exitCmd;
protected Command debugCmd;
protected Display display;
protected String debug;
public MidletState() {
addDebugInfo("In MidletState()");
display = Display.getDisplay(this);
form = new Form("Hello world.");
form.append("What a new world!");
exitCmd = new Command("Exit", Command.EXIT, 1);
debugCmd = new Command("Debug", Command.SCREEN, 2);
form.addCommand(exitCmd);
form.addCommand(debugCmd);
form.setCommandListener(this);
}
/**
* startApp
*/
protected void startApp() {
addDebugInfo("In startApp()");
display.setCurrent(form);
}
/**
* pauseApp
*/
protected void pauseApp() {
addDebugInfo("In pauseApp()");
}
/**
* destroyApp
*
* @param boolean0 boolean
*/
protected void destroyApp(boolean boolean0) {
addDebugInfo("In destroyApp(" + boolean0 + ")");
}
/**
* commandAction
*
* @param command Command
* @param displayable Displayable
*/
public void commandAction(Command command, Displayable displayable) {
addDebugInfo("In commandAction(...)");
if (command == exitCmd) {
destroyApp(true);
notifyDestroyed();
}
else if (command == debugCmd) {
notifyUser(debug, form);
}
}
protected String addDebugInfo(String debugMsg) {
if (debug == null) {
debug = new String();
}
debug = debug.concat(debugMsg + "\n");
return debugMsg;
}
protected void notifyUser(String message, Displayable screen) {
Alert alert = new Alert("Info", message, null, AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, screen);
}
}
下一篇:J2ME相关名词解释及概念阐述 >>
相关文章:
- · J2ME 3D编程——第一个3D程序
- · J2ME学习笔记(六)
- · J2ME学习笔记(五)
- · J2ME开发工具和厂商SDK介绍
- · J2ME HELLOWORLD 小试牛刀
- · J2ME学习笔记(四)
- · J2ME学习笔记(三)
- · J2ME学习笔记(二)
- · J2ME学习笔记(一)
- · J2ME游戏中读入文本并存储在String数组中
- · 介绍J2ME的几个重要概念
- · J2ME学习(四)——将MIDlet和界面分离(比较基础)
- · J2ME学习(三)——如何播放声音
- · 学习J2ME编程需要掌握的七种技术
- · J2EE探索者:隐式对象的多种用法
- · J2ME小游戏-fly
- · J2ME Timer 使用指南
- · J2ME MIDP Currency Converter Tutorial for NetBeans IDE 4.0
- · JavaWebStudio 2005开发J2ME方法
- · J2ME学习笔记(1)--实现手机屏幕的切换
- · J2EE平台介绍
- · J2ME手机游戏开发日记1
- · J2ME中对Image的缩放
- · J2ME中对Image的缩放
- · 如何在J2ME的低级界面中轻松实现各种文字的自然分行显示
- · j2me游戏引擎程序结构
- · j2me getProperty
- · J2ME开发环境安装指南
- · J2ME 2D小游戏入门之旅(七) 不足多多,你认为呢?
- · J2ME 2D小游戏入门之旅(六) 计时器和奖惩与评价
- · J2ME 2D小游戏入门之旅(五) 实现爆炸效果、并加入道具导弹
- · J2ME 2D小游戏入门之旅(四) 加入子弹群,实现碰撞运算
- · J2ME开发笔记-键盘响应
- · J2ME 2D小游戏入门之旅(三) 控制飞机的移动
- · J2ME 2D小游戏入门之旅(二)完善周边工具类
- · J2ME 2D小游戏入门之旅(一)游戏的框架
- · J2ME Read Cookies
- · 用EclipseME0.5.5创建一个简单的J2ME程序
