package FillSpace;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
public class Fs extends Form implements CommandListener{
//定义命令 退出、答题、提交
private Command exit;
private Command dt;
private Command tj;
public Fs(String title) {
super(title);
//绘制窗体内容加载到Form
this.append("第一题:9×8=()");
//初始化按钮并加载命令 最后针对此窗体监听
exit=new Command("退出",Command.EXIT,1);
dt=new Command("答题",Command.OK,1);
tj=new Command("提交",Command.OK,1);
this.addCommand(exit);
this.addCommand(dt);
this.addCommand(tj);
this.setCommandListener(this);
// TODO Auto-generated constructor stub
}
public void commandAction(Command cmd, Displayable arg1) {
// TODO Auto-generated method stub
if(cmd==exit){
//退出(调用close方法)
Main.close();
}else if(cmd==dt){
//答题 直接显示填充答案窗体
Display.getDisplay(Main.main).setCurrent(Main.fill);
}else if(cmd==tj){
//提交 这里需要判断 只做了简单的分析
if(Main.answer.equals("72")){
//如果等于72 则回答正确 初始化提示框 然后显示
Alert alt=new Alert("结果","您的回答正确!",null,AlertType.INFO);
Display.getDisplay(Main.main).setCurrent(alt,this);
}else{
//如果不等于72 则回答错误 初始化提示框 然后显示
Alert alt=new Alert("结果","您的回答错误!",null,AlertType.INFO);
Display.getDisplay(Main.main).setCurrent(alt,this);
}
}
}
}