Alert主要的作用是可以显示信息(错误、异常和用户提示等),可以包括文本或者图像。它可以设置为在等待某一段时间后,自动跳到下一屏。
下边的代码说明了如何在MIDlet里使用Alert
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class alertMidlet extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command alertCommand;
private Display display;
private TextBox tb;
public alertMidlet()
{
exitCommand = new Command("Exit", Command.EXIT, 1);
alertCommand = new Command("Alert", Command.SCREEN, 1);
tb = new TextBox("Alert MIDLET", "Main Screen", 25, 0);
}
protected void startApp()
{
tb.addCommand(exitCommand);
tb.addCommand(alertCommand);
tb.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(tb);
}
protected void pauseApp() {}
protected void destroyApp(boolean bool) {}
public void commandAction(Command cmd, Displayable disp)
{
if (cmd == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
else if (cmd == alertCommand)
{
Alert at = new Alert("Alert", "Alert Screen",
null, AlertType.INFO);
display.setCurrent(at);
}
}
}
本文介绍如何在MIDlet应用中使用Alert组件来显示信息,如错误、异常或用户提示等,并通过示例代码展示了如何创建Alert及触发显示。
606

被折叠的 条评论
为什么被折叠?



