Chinaunix首页 | 论坛 | 博客
  • 博客访问: 460075
  • 博文数量: 155
  • 博客积分: 2954
  • 博客等级: 少校
  • 技术积分: 1000
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-12 22:00
文章分类

全部博文(155)

文章存档

2014年(2)

2013年(5)

2012年(10)

2011年(33)

2010年(105)

我的朋友

分类: 嵌入式

2010-11-30 16:39:37

下面的代码介绍了如何使用Alert来创建一个确认对话框。

import javax.microedition.midlet.*; import javax.microedition.lcdui.*;   public class ConfirmationMIDlet extends MIDlet implements CommandListener { private Form form; private Alert alert; private Command exitCommand;   public void startApp() { form = new Form("ConfirmationMIDlet"); exitCommand = new Command("Exit", Command.EXIT, 1); form.setCommandListener(this); form.addCommand(exitCommand); Display.getDisplay(this).setCurrent(form); }   public void pauseApp() { }   public void destroyApp(boolean unconditional) { }   public void commandAction(Command c, Displayable d) { if (c == exitCommand) { showConfirmation("Confirmation", "Do you really want to exit?"); } }   private void closeAlert() { Display.getDisplay(this).setCurrent(form); alert = null; }   protected void showConfirmation( title, text) { alert = new Alert(title, text, null, AlertType.CONFIRMATION); alert.addCommand(new Command("Yes", Command.OK, 1)); alert.addCommand(new Command("No", Command.CANCEL, 1)); alert.setCommandListener(new CommandListener() { public void commandAction(Command c, Displayable d) { if (c.getLabel().equals("Yes")) { notifyDestroyed(); } if (c.getLabel().equals("No")) { closeAlert(); } } }); Display.getDisplay(this).setCurrent(alert, form); } }
阅读(564) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~