Ejemplo n.º 1
0
    @Override
    public void actionPerformed(ActionEvent arg) {
      String mes = "";
      int it = 1;

      // for all of the answers of the challenger check if its true or false
      // add points if he answered good
      // add the good answers if not
      // and show it in a dialogBox.
      for (AnswerUI ans : QuestionnaireUI.this.answers) {
        if (ans.getAnswer().checkAnswer(ans.getValue()))
          QuestionnaireUI.this.points += ans.getQuestion().getPoints();
        else
          mes +=
              "Q"
                  + it
                  + " : Wrong the correct answer was : "
                  + ans.getAnswer().getCorrectAnswer()
                  + "\n";

        it++;
      }

      mes += "\nYou have won " + QuestionnaireUI.this.points + " points";

      JOptionPane.showMessageDialog(frame, mes);
    }
Ejemplo n.º 2
0
  /**
   * Instantiates a new questionnaireUI.
   *
   * @param q the questionnaire
   */
  public QuestionnaireUI(Questionnaire q) {
    this.answers = new ArrayList<AnswerUI>();
    this.frame = new JFrame("Questionnaire");
    this.frame.setLayout(new GridLayout(q.getNumberOfQuestions() + 1, 2));

    // add all the Answers to a List
    for (Question quest : q.getQuestions()) {
      this.answers.add(quest.getAnswer().getUI(quest));
    }

    // use that List to create the frame
    for (AnswerUI ans : this.answers) {
      this.frame.add(new JLabel(ans.getQuestion().getQuestion()));
      this.frame.add(ans.getPanel());
    }

    this.submit = new JButton("submit");
    this.submit.addActionListener(new SubmitAnswers());

    this.frame.add(this.submit);

    this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.frame.pack();
    this.frame.setVisible(true);
  }