Current Position:Home > Help Making a Quiz MIDlet

Help Making a Quiz MIDlet

Update:11-30Source: network consolidation
Advertisement
Hi, I'm relatively new to Java and programming in general so I'm having some difficulty developing a quiz MIDlet. I would like to have users navigate from screen to screen for each question. So far I was able to add one ChoiceGroup, but I'm having difficulty creating multiple ChoiceGroups on different screens (I would like at least 10). Also, how can I make sure that the gauge I've made is incremental and updates for each different screen?
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class PracticeOne extends MIDlet
implements CommandListener {
Display display;
List menu;
String[] answers = {"Answer 1", "Answer 2", "Answer 3"};
ChoiceGroup question =new ChoiceGroup("Question", ChoiceGroup.EXCLUSIVE, answers, null);
Form form = new Form("Practice Quiz");
Gauge gauge = new Gauge("Progress", false, 10, 0);
static final Command backCommand =
new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand =
new Command("Main", Command.SCREEN, 1);
static final Command okCommand =
new Command("OK", Command.SCREEN, 0);
static final Command updateCommand =
new Command("Update", Command.SCREEN, 0);
static final Command exitCommand =
new Command("Exit", Command.STOP, 2);
String currentMenu;
public PracticeOne() {
public void startApp() throws
MIDletStateChangeException {
display = Display.getDisplay(this);
menu = new List(
"Practice Quiz", Choice.IMPLICIT);
menu.append("Start Quiz", null);
menu.addCommand(exitCommand);
menu.setCommandListener(this);
mainMenu();
// form
form.append(gauge);
form.append(this.question);
public void pauseApp() {
display = null;
menu = null;
form = null;
gauge = null;
public void destroyApp(boolean unconditional) {
notifyDestroyed();
void mainMenu() {
display.setCurrent(menu);
currentMenu = "Main";
public void testForm() {
form.addCommand(backCommand);
form.addCommand(okCommand);
form.setCommandListener(this);
display.setCurrent(form);
currentMenu = "form";
public void commandAction(Command c,
Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Back")) {
if(currentMenu.equals("list")
|| currentMenu.equals("input") ||
currentMenu.equals("date")
|| currentMenu.equals("form")) {
mainMenu();
} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: testForm();break;
}Thanks in advance for any advice/tips,
ailame :)

The Best Answer

Advertisement
I followed your advice, but for some reason I can only navigate to only one form. I've made five forms in total with five choicegroups each. Unfortunately I can only access the first form and the second form. Here's the new code again:
public class PracticeOne extends MIDlet
implements CommandListener {
     Display display;
     List menu;
     String[] answers = {"Answer 1", "Answer 2", "Answer 3"};
     ChoiceGroup question =new ChoiceGroup("Question", ChoiceGroup.EXCLUSIVE, answers, null);
     Form form = new Form("Practice Quiz");
     String[] answerstwo = {"Answer 1", "Answer 2", "Answer 3"};
     ChoiceGroup questiontwo =new ChoiceGroup("Question 2", ChoiceGroup.EXCLUSIVE, answerstwo, null);
     Form formtwo = new Form("Practice Quiz");
     String[] answersthree = {"Answer 1", "Answer 2", "Answer 3"};
     ChoiceGroup questionthree =new ChoiceGroup("Question 3", ChoiceGroup.EXCLUSIVE, answersthree, null);
     Form formthree = new Form("Practice Quiz");
     String[] answersfour = {"Answer 1", "Answer 2", "Answer 3"};
     ChoiceGroup questionfour =new ChoiceGroup("Question 4", ChoiceGroup.EXCLUSIVE, answersfour, null);
     Form formfour = new Form("Practice Quiz");
     String[] answersfive = {"Answer 1", "Answer 2", "Answer 3"};
     ChoiceGroup questionfive =new ChoiceGroup("Question 5", ChoiceGroup.EXCLUSIVE, answersfive, null);
     Form formfive = new Form("Practice Quiz");
     Gauge gauge = new Gauge("Progress", false, 5, 0);
     static final Command backCommand =
          new Command("Back", Command.BACK, 0);
     static final Command mainMenuCommand =
          new Command("Main", Command.SCREEN, 1);
     static final Command okCommand =
          new Command("OK", Command.OK, 0);
     static final Command updateCommand =
          new Command("Update", Command.SCREEN, 0);
     static final Command exitCommand =
          new Command("Exit", Command.STOP, 2);
     String currentMenu;
     public PracticeOne() {
     public void startApp() throws
          MIDletStateChangeException {
               display = Display.getDisplay(this);
               menu = new List(
                                   "Practice Quiz", Choice.IMPLICIT);
               menu.append("Start Quiz", null);
               menu.addCommand(exitCommand);
               menu.setCommandListener(this);
               mainMenu();
               form.append(gauge);
               form.append(this.question);
               formtwo.append(gauge);
               formtwo.append(this.questiontwo);
               formthree.append(gauge);
               formthree.append(this.questionthree);
               formfour.append(gauge);
               formfour.append(this.questionfour);
               formfive.append(gauge);
               formfive.append(this.questionfive);
     public void pauseApp() {
          display = null;
          menu = null;
          form = null;
          gauge = null;
          formtwo = null;
          formthree = null;
          formfour = null;
          formfive = null;
     public void destroyApp(boolean unconditional) {
          notifyDestroyed();
     void mainMenu() {
          display.setCurrent(menu);
          currentMenu = "Main";
     public void testForm() {
          form.addCommand(exitCommand);
          form.addCommand(okCommand);
          form.setCommandListener(this);
          display.setCurrent(form);
          currentMenu = "form";
     public void testForm2() {
          formtwo.addCommand(exitCommand);
          formtwo.addCommand(okCommand);
          formtwo.setCommandListener(this);
          display.setCurrent(formtwo);
          currentMenu = "formtwo";
     public void testForm3() {
          formthree.addCommand(exitCommand);
          formthree.addCommand(okCommand);
          formthree.setCommandListener(this);
          display.setCurrent(formthree);
          currentMenu = "formthree";
     public void testForm4() {
          formfour.addCommand(exitCommand);
          formfour.addCommand(okCommand);
          formfour.setCommandListener(this);
          display.setCurrent(formfour);
          currentMenu = "formfour";
     public void testForm5() {
          formfive.addCommand(exitCommand);
          formfive.addCommand(okCommand);
          formfive.setCommandListener(this);
          display.setCurrent(formfive);
          currentMenu = "formfive";
     public void commandAction(Command c,
                                     Displayable s) {
          String label = c.getLabel();
          if (label.equals("Exit")) {
               destroyApp(true);
          } else if (label.equals("Back")) {
               if(currentMenu.equals("form")) {
                    mainMenu();
          } else if (label.equals("OK")) {
               if(currentMenu.equals("form")) {
                    testForm2();
          } else if (label.equals("OK")) {
               if(currentMenu.equals("formtwo")) {
                    testForm3();
          } else if (label.equals("OK")) {
               if(currentMenu.equals("formthree")) {
                    testForm4();
          } else if (label.equals("OK")) {
               if(currentMenu.equals("formfour")) {
                    testForm5();
          } else {
               List down = (List)display.getCurrent();
               switch(down.getSelectedIndex()) {
                    case 0: testForm();break;
}I can't see where the problem is exactly. Also, what code can I use to record a user's choice in the choicegroup?
Message was edited by:
ailame
  • Help Making a Quiz MIDlet Update:11-30

    Hi, I'm relatively new to Java and programming in general so I'm having some difficulty developing a quiz MIDlet. I would like to have users navigate from screen to screen for each question. So far I was able to add one ChoiceGroup, but I'm having di

  • Displaying a quiz in midlet Update:11-30

    hello everyone, i am new to j2me, can anyone help how to develop a quiz in a j2me midlet. as i am unable to print not more than one question using forms. thanks in advance regards pallavipublic class CheckBoxExample extends MIDlet implements CommandL

  • Creating multi forms  in a midlet Update:11-30

    hi everyone, i want to create a quiz, here i would like to know how to cal one form another.. anyone can help me. here i am giving my code.. i am new to j2me, i dnt knw how to cal 2nd from into command action public class Quiz3 extends MIDlet impleme

  • How can I deal with negative marking in a quiz marking scheme? Update:10-11

    I wonder if anyone can help me with a problem I have in developing the 'code' for a marking scheme for an exam in Captivate 8. I would be very grateful for pointers towards a viable solution. At the moment I am just thrashing around. My background is

  • How do I only get certain questions appear in the quiz results? Update:10-11

    I have created a course through Captivate 6, throughout the course there are questions to guage the learners attention. There is also a quiz at the end. However, captivate includes on the questions throughout the course on the quiz results which I do

  • (Self-)signing a MIDlet for use on ~10 phones without spending money Update:10-11

    Hello everyone, I just spend like 4 hours researching how to sign MIDlet and I am totally confused. Instead of asking for general instructions I am going to explain what I want to do. Hopefully that will enable people to tell me whether or not this i

  • [Contest] Total War: Attlia Daily Quiz! Update:10-11

    Gamers! it's the time to show your gaming spirit and knowledge!! Answer the quiz of day to win the free MSI A88XM GAMING Motherboard, Tt eSPORTS Gaming Gears, and Total War: Attlia Game Code! ***Date*** 2015/04/27 - 2015/05/11 Quiz Platform:MSI Twitt

  • How to send quiz results to a web page? Update:10-11

    Okay, this should have taken 2 minutes, not 2 hours. Very frustrating. Here is the situation: * Downloaded Captivate 5 Trial Version * Created based quiz (which took forever to figure out how to set the correct answers -- HORRIBLE user interface for

  • Enlarging photos and quiz Update:10-11

    I am new to flash and working on a project for a class. I am working with mx 2004. I want to be able to have the user rollover or click on a small picture and have it show up larger in another part of the window. I know its possible but I can't figur

  • How do I incorporate text entry boxes into a quiz? Update:10-11

    Hi Everyone, I am very new to Captivate 8. I am trying to incorporate TEB's into a quiz. When I try to check the button (include in quiz) it is grey and does not allow me to check it. In addition I do not know how to let the programme know what text