您的位置:首页 > 其它

moto List一个有趣的问题

2008-04-25 15:26 405 查看
/*
*
* Copyright © 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
package list;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

/**
* The MIDlet demonstrates the different types of list supported by MIDP-2.0:
* EXCLUSIVE - a choice having exactly one element selected at time.
* IMPLICIT - a choice in which the currently focused element is
* selected when a Command is initiated.
* MULTIPLE - a choice that can have arbitrary number of elements
* selected at a time.
*
* @version 2.0
*/
public class ListDemo extends MIDlet implements CommandListener {
private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 1);
private static final Command CMD_BACK = new Command("Back", Command.BACK, 1);
private Display display;
private List mainList;
private List exclusiveList;
private List implicitList;
private List multipleList;
private boolean firstTime;

public ListDemo() {
display = Display.getDisplay(this);

// these are the strings for the choices.
String[] stringArray = {
"Rowboating(420/0.5hour)",
"Spin and weave(400/0.5hour)",
"Playing squash(360/0.5hour)",
"Judo(300/0.5hour)",
"Fencing(300/0.5hour)",
"Swimming(273/0.5hour)",
"Boxing(225/0.5hour)",
"Rope Skipping(224/0.5hour)",
"Sit-ups(216/0.5hour)",
"Playing football(210/0.5hour)",
"Playing basketball(200/0.5hour)",
"Aerobic(190/0.5hour)",
"Skiing(177/0.5hour)",
"Playing tennis(176/0.5hour)",
"Running(176/0.5hour)",
"Weight lifting(165/0.5hour)",
"Hiking(150/0.5hour)",
"Mark time machine(150/0.5hour)",
"Stepping(141/0.5hour)",
"Horse riding(138/0.5hour)",
"Playing badminton(135/0.5hour)",
"Playing snooker(135/0.5hour)",
"Aerobic exercise(126/0.5hour)",//
"Playing table tennis(120/0.5hour)",
"Take a sharp walk(114/0.5hour)",
"Jogging(112/0.5hour)",
"Dancing(102/0.5hour)",
"Cycling(92/0.5hour)",
"Playing volleyball(90/0.5hour)",
"Playing bowling(90/0.5hour)",
"Take a walk(66/0.5hour)",
"Golfing(43/0.5hour)",
};

// the string elements will have no images
Image[] imageArray = null;

/*
* create samples of the supported types:
* "Exclusive", "Implicit" and "Multiple"
*/
exclusiveList = new List("Exclusive", Choice.EXCLUSIVE, stringArray, imageArray);
exclusiveList.addCommand(CMD_BACK);
exclusiveList.addCommand(CMD_EXIT);
exclusiveList.setCommandListener(this);

implicitList = new List("Implicit", Choice.IMPLICIT, stringArray, imageArray);
implicitList.addCommand(CMD_BACK);
implicitList.addCommand(CMD_EXIT);
implicitList.setCommandListener(this);

multipleList = new List("Multiple", Choice.MULTIPLE, stringArray, imageArray);
multipleList.addCommand(CMD_BACK);
multipleList.addCommand(CMD_EXIT);
multipleList.setCommandListener(this);

firstTime = true;
}

protected void startApp() {
if (firstTime) {
// these are the images and strings for the choices.
Image[] imageArray = null;

try {
// load the duke image to place in the image array
Image icon = Image.createImage("/midp/uidemo/Icon.png");

// these are the images and strings for the choices.
imageArray = new Image[] { icon, icon, icon };
} catch (java.io.IOException err) {
// ignore the image loading failure the application can recover.
}

String[] stringArray = { "Exclusive", "Implicit", "Multiple" };
mainList = new List("Choose type", Choice.IMPLICIT, stringArray, imageArray);
mainList.addCommand(CMD_EXIT);
mainList.setCommandListener(this);
display.setCurrent(mainList);
firstTime = false;
}
}

protected void destroyApp(boolean unconditional) {
}

protected void pauseApp() {
}

public void commandAction(Command c, Displayable d) {
if (d.equals(mainList)) {
// in the main list
if (c == List.SELECT_COMMAND) {
if (d.equals(mainList)) {
switch (((List)d).getSelectedIndex()) {
case 0:
display.setCurrent(exclusiveList);

break;

case 1:
display.setCurrent(implicitList);

break;

case 2:
display.setCurrent(multipleList);

break;
}
}
}
} else {
// in one of the sub-lists
if (c == CMD_BACK) {
display.setCurrent(mainList);
}
}

if (c == CMD_EXIT) {
destroyApp(false);
notifyDestroyed();
}
}
}
这个程序用moto EM30测试时 选MULTIPLE时会发现最后一行只有一半。
还有一个问题 是 如果程序运行时 中断返回到待机画面,修改话机的时间(时间如果调为将来的某个时间)在中断返回是没有问题的,如果修改话机的时间(时间调为比当前手机中时间更早的时间)则会导致程序返回时有异常现象(比如屏幕停滞,无法响应按键事件)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: