Example #1
0
  public void actionIfCustom(String recup) {

    // test
    if (recup.equals(((QuestionCustom) e.getQuestion(iterateur - 1)).getSolutionString())) {
      practice.addRight(iterateur - 1);
    } else {
      practice.addWrong(iterateur - 1);
    }
  }
Example #2
0
  public void actionIfEquation(String recup) {

    // réponse
    double anwser = new Double(recup);

    // test
    if (anwser == ((QuestionEquation) e.getQuestion(iterateur - 1)).solve()[1]) {
      practice.addRight(iterateur - 1);
    } else {
      practice.addWrong(iterateur - 1);
    }
  }
Example #3
0
 public void action(String stringRecup) {
   if (stringRecup.equals("")) {
     practice.addWrong(iterateur - 1);
   } else {
     switch (e.getType()) {
       case "calculation":
         actionIfCalculation(stringRecup);
         break;
       case "fraction":
         actionIfFraction(stringRecup);
         break;
       case "power":
         actionIfPower(stringRecup);
         break;
       case "equation":
         actionIfEquation(stringRecup);
         break;
       case "custom":
         actionIfCustom(stringRecup);
         break;
     }
   }
 }
Example #4
0
  public void setPanCenter() {
    iterateur++;
    panCenter = new JPanel();

    // Définition de la taille
    panCenter.setBackground(new Color(45, 45, 45));
    panCenter.setPreferredSize(new Dimension(fen.width, 400));

    // On test si on arrive à la fin de l'exercice
    if (isFini()) {

      practice.updateSuccess();

      // Affichage
      panCenter.add(
          new BmgLabel(
              "<br/><br/>C'est fini !"
                  + "<br/><br/>Score : "
                  + practice.getSuccess()
                  + "%"
                  + "<br/><br/>Mauvaise(s) réponse(s) : "
                  + practice.getWrong_answersString()
                  + "<br/><br/>Temps d'execution : "
                  + practice.getExecution_time()
                  + "sec"
                  + "<br/><br/>Date d'execution : "
                  + practice.getExecution_dateString(),
              "white",
              14));

    } else {

      JPanel panCenter1 = new JPanel();

      panCenter1.setPreferredSize(new Dimension(fen.width - 199, 349));
      panCenter1.setBackground(new Color(45, 45, 45));

      // Si c'est pas fini on continue
      JLabel lab =
          new JLabel(
              "<html><p style=\"color: orange;font-size: 14px;\">Question "
                  + iterateur
                  + " / "
                  + getNombreDeQuestions()
                  + "</p><br/><p style=\"color: white;font-size:13px;\">"
                  + e.getQuestionText(iterateur - 1)
                  + "</p>");
      lab.setPreferredSize(new Dimension(fen.width - 200, 100));

      panCenter1.add(lab);

      // Champ de saisie
      final JTextField saisie = new JTextField(30);
      saisie.setPreferredSize(new Dimension(50, 30));

      saisie.setEnabled(true);

      KeyListener key =
          new KeyListener() {

            @Override
            public void keyTyped(KeyEvent ke) {}

            @Override
            public void keyPressed(KeyEvent ke) {
              if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
                // if enter
                action(saisie.getText());
                setPanel();
              }
            }

            @Override
            public void keyReleased(KeyEvent ke) {}
          };

      saisie.addKeyListener(key);

      panCenter1.add(saisie);
      panCenter.add(panCenter1);

      // Next
      JButton next = new JButton("Suivant");
      // Listener
      next.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
              // System.out.println("Valeur de l'itérateur : " + iterateur);

              action(saisie.getText());
              setPanel();
            }
          });

      // Add button
      panCenter.add(next);
    }
  }