Alert用法一例

| No Comments | No TrackBacks
/*
* 显示一个Alert的屏幕
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class TextBox_Alert extends MIDlet implements CommandListener {
private Command exitCommand,alertCommand;
private TextBox tb;
public TextBox_Alert() {
exitCommand = new Command("Exit", Command.EXIT, 1);
alertCommand = new Command("Alert", Command.SCREEN, 1);
tb = new TextBox("Alert MIDlet", "Alert Example!", 15, 0);

tb.addCommand(exitCommand);
tb.addCommand(alertCommand);

tb.setCommandListener(this);

}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(tb);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0){
}
public void commandAction(Command c, Displayable d) {

if(d == tb && c == alertCommand){

Image img;
try{
img = Image.createImage("/Icon.png");
}
catch(java.io.IOException e){
img = null;
}

Alert info = new Alert("Alert","This is a Alert Example!",img ,AlertType.INFO);
info.setTimeout(Alert.FOREVER);

//Display.getDisplay(this).setCurrent(info,tb);
Display.getDisplay(this).setCurrent(info);
}

if (c == exitCommand) {

destroyApp(false);
notifyDestroyed();
}
}
}

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/1740

Leave a comment

相关文档

上一篇:用Lucene-1.3-final为网站数据库建立索引 .

下一篇:使用缓存将屏幕内容存储为Image