class DialogForm extends Form implements CommandListener{//UI部分
Command yesCMD;
Command noCMD;
Dialog dialog;
public DialogForm(Dialog dialog,String title,String content,String yes,String no) {
super(title);
this.dialog=dialog;
append(content);
yesCMD=new Command(yes,Command.OK,1);
noCMD=new Command(no,Command.CANCEL,1);
addCommand(yesCMD);
addCommand(noCMD);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
if(c==yesCMD){
dialog.setBlockFlag(true);
dialog.setReturnValue(Dialog.YES);
dialog.wakeup();
}else if(c==noCMD){
dialog.setBlockFlag(true);
dialog.setReturnValue(Dialog.NO);
dialog.wakeup();
}
}
}
如何使用
我编写了一个Test。当用户按下show按钮时,开启对话框,并将用户的选择打印出来。