Bem galera, estou desenvolvendo um quiz em J2ME e não estou conseguindo fazer com que ele avance para a próxima tela.
Criei um Display para armazenar o 1º quastionário com choicegroup exclusive e um form para exibir a resposta selecionada, só que agora não consigo avançar desse form para ir para um novo Display e criar uma nova questão, assim por diante.
Se alguém puder me ajudar eu agradeço.
Segue o código abaixo:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.midlet.MIDlet;
public class CheckBox extends MIDlet implements CommandListener {
private boolean midletPaused = false;
private Form form;
private ChoiceGroup choiceGroup;
private Form form1;
private Command okCommand;
private Command exitCommand;
private Command okCommand1;
private int index;
private Display display;
private ChoiceGroup choiceGroup1;
public CheckBox() {
form = new Form("Technologies");
choiceGroup = new ChoiceGroup("Quem descobriu o Brasil?", Choice.EXCLUSIVE);
exitCommand = new Command("Exit", Command.EXIT, 1);
okCommand = new Command("OK", Command.SCREEN, 2);
}
public void commandAction(Command command, Displayable displayable) {
// write pre-action user code here
String label = command.getLabel();
if (label.equals("OK")) {
StringItem message[] = new StringItem[choiceGroup.size()];
boolean get[] = new boolean[choiceGroup.size()];
choiceGroup.getSelectedFlags(get);
for (int i = 0; i < get.length; i++) {
if (get[i]) {
message[i] = new StringItem("A SUA RESPOSTA É: ", choiceGroup.getString(i));
form.append(message[i]);
}
}
form.delete(index);
form.removeCommand(okCommand);
} else if (label.equals("EXIT")){
destroyApp(false);
}
}
public Display getDisplay () {
return Display.getDisplay(this);
}
public void exitMIDlet() throws MIDletStateChangeException {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
display = Display.getDisplay(this);
choiceGroup.append("Cristovão Colombo", null);
choiceGroup.append("Napoleão Bonaparte", null);
choiceGroup.append("Tiradentes", null);
choiceGroup.append("D. Pedro I", null);
index = form.append(choiceGroup);
form.addCommand(exitCommand);
form.addCommand(okCommand);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}