日期:2014-05-20  浏览次数:20794 次

!!!!!!J2ME图形菜单的示例代码!!!!!!!!!!!!
J2ME图形菜单的例子代码,那位有收藏,能传授给小弟学习学习啊``````

------解决方案--------------------
/**使用list显示带有图标的list项*/
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class ListTest extends MIDlet implements CommandListener {

private List list;

private Display display;

private Image[] imageArray;

private Image image;

private Command exitCommand, backCommand, okCommand;

private TextBox tb;

public ListTest() {
// TODO Auto-generated constructor stub
display = Display.getDisplay(this);

exitCommand = new Command( "EXIT ", Command.EXIT, 1);
backCommand = new Command( "BACK ", Command.BACK, 1);
okCommand = new Command( "OK ", Command.OK, 1);

tb = new TextBox( "信息 ", " ", 120, TextField.ANY);//注意这里的 最大长度,如果太小会报非法参数异常
tb.addCommand(exitCommand);
tb.addCommand(backCommand);
tb.setCommandListener(this);

try {
image = Image.createImage( "/icon.png ");
} catch (java.io.IOException err) {
System.out.print( "加载图片失败 ");
}

imageArray = new Image[] { image, image, image, image };

String info[] = new String[] { "删除信息 ", "浏览信息 ", "编辑信息 ", "查找信息 " };

list = new List( "收件箱 ", List.MULTIPLE, info, imageArray);

list.setCommandListener(this);

list.addCommand(exitCommand);
list.addCommand(okCommand);
list.setCommandListener(this);

}

public void commandAction(Command arg0, Displayable arg1) {
// TODO Auto-generated method stub

String str[] = new String[] { "选择了删除信息 ", "选择了浏览信息 ", "选择了编辑信息 ",
"选择了查找信息 " };

boolean choice[] = new boolean[4];

if (arg1.equals(list)) {

if (arg0 == okCommand) {
list.getSelectedFlags(choice);
String out = " ";
for (int i = 0; i < choice.length; i++) {
if (choice[i] == true) {
out = out + str[i] + "\n ";

}
tb.setString(out);

display.setCurrent(tb);

}

}
}

if (arg0 == exitCommand) {

notifyDestroyed();
}
if (arg0 == backCommand) {
display.setCurrent(list);
}

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
// display.setCurrent(tb);
display.setCurrent(list);

}

}