当前位置:IT168首页 > 技术开发 >
[收藏此页] [打印] [推荐] [评论]

用Alert创建确认对话框

责任编辑:ITPUB实习编辑作者:ITPUB论坛   2008-07-07   
文本Tag: J2ME
下面的代码介绍了如何使用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(String title, String 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); } }
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
  • 第1页:
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/jd/2008-07-07/200807071436825.shtml
技术开发相关文章  
  • 暂无
友情推介