字符元素开发 StringItemDemo.java

import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
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.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;


public class StringItemDemo extends MIDlet implements CommandListener,
ItemCommandListener {

private Display display;

private Form mainForm;
private final static Command CMD_GO = new Command("Go",Command.ITEM,1);
private final static Command CMD_PRESS = new Command("Press",Command.ITEM,1);
//private final static Command CMD_SHOW = new Command("Show",Command.SCREEN,1);
private final static Command CMD_EXIT = new Command("Exit",Command.EXIT,1);

protected void destroyApp(boolean arg0) {
}

protected void pauseApp() {
}

protected void startApp() {
display = Display.getDisplay(this);

mainForm = new Form("String Item Demo");
mainForm.append("This is a simple label");

StringItem item = new StringItem("This is a StringItem label: ",
"This is the StringItems text");
mainForm.append(item);
item = new StringItem("Short label: ","text");
mainForm.append(item);
//超链接
item = new StringItem("Hyper-Link ","hyperlink",Item.HYPERLINK);
item.setDefaultCommand(CMD_GO);
item.setItemCommandListener(this);
mainForm.append(item);
item = new StringItem("Button ","Button",Item.BUTTON);
item.setDefaultCommand(CMD_PRESS);
//item.setDefaultCommand(CMD_SHOW);
item.setItemCommandListener(this);
mainForm.append(item);
mainForm.addCommand(CMD_EXIT);
mainForm.setCommandListener(this);
display.setCurrent(mainForm);
}

public void commandAction(Command c, Displayable d) {
destroyApp(false);
notifyDestroyed();
}

public void commandAction(Command c, Item item) {
if(c == CMD_GO) {
try {
String text = "Go to the URL...";
Image image = Image.createImage("/Icon.png");
Alert a = new Alert("URL",text,image,AlertType.INFO);
display.setCurrent(a);
} catch (IOException e) {
e.printStackTrace();
}
}else if(c == CMD_PRESS){
String text = "Do an action...";
Alert a = new Alert("Action",text,null,AlertType.INFO);
display.setCurrent(a);
}
// else if(c == CMD_SHOW){
// try {
// String text = "Go to the URL...";
// Image image = Image.createImage("/Icon.png");
// Alert a = new Alert("URL",text,image,AlertType.INFO);
// display.setCurrent(a);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值