Example #1
0
    public void actionPerformed(ActionEvent e) {
      String UCID = textField.getText();
      String Password = String.valueOf(passwordField.getPassword());
      if (!UCID.isEmpty() && !Password.isEmpty()) {
        Person p = new Person();
        p.UCID = UCID;
        p.Password = Password;
        Client cl = new Client();
        String Send = "start" + "|" + Person.ConvertToString(p);
        System.out.println(Send);
        String Receive = cl.login(Send);
        label.setText(p.UCID);
        System.out.println(Receive);
        String[] msg = Receive.split("\\|");
        if (msg[0].equalsIgnoreCase("confirm")) {
          CardLayout cards = (CardLayout) contentPane.getLayout();
          cards.show(contentPane, "student");

          i = 1;
          String j = String.valueOf(i);
          Question c = new Question();
          Send = "question" + "|" + i;
          System.out.println(Send);
          Receive = cl.login(Send);
          c = Question.ConverToObject(Receive);
          textPane.setText(c.Question);
          answerTF[i - 1] = c.Answer;
        }
      }
    }
Example #2
0
  private void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree_1.getLastSelectedPathComponent();
    String option = (String) node.getUserObject();
    CardLayout cards = (CardLayout) student.getLayout();
    CardLayout cards1 = (CardLayout) content.getLayout();
    if (option.equals("1")) {
      i = 1;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      System.out.println(answerTF[i - 1]);
      BG1.clearSelection();

    } else if (option.equals("2")) {
      i = 2;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG1.clearSelection();
    } else if (option.equals("3")) {
      i = 3;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG1.clearSelection();
    } else if (option.equals("4")) {
      i = 4;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG1.clearSelection();
    } else if (option.equals("5")) {
      i = 5;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG1.clearSelection();
    } else if (option.equals("6")) {
      i = 6;
      cards1.show(content, "Question_T");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG1.clearSelection();

    } else if (option.equals("7")) {
      i = 7;

      cards1.show(content, "Question_M");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane_1.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG2.clearSelection();

    } else if (option.equals("8")) {
      i = 8;
      cards1.show(content, "Question_M");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane_1.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG2.clearSelection();
    } else if (option.equals("9")) {
      i = 9;
      cards1.show(content, "Question_M");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane_1.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG2.clearSelection();
    } else if (option.equals("10")) {
      i = 10;
      cards1.show(content, "Question_M");
      String j = String.valueOf(i);
      Question p = new Question();
      Client cl = new Client();
      String Send = "question" + "|" + i;
      System.out.println(Send);
      String Receive = cl.login(Send);
      p = Question.ConverToObject(Receive);
      textPane_1.setText(p.Question);
      answerTF[i - 1] = p.Answer;
      BG2.clearSelection();

    } else if (option.equals("Submit")) {

      cards1.show(content, "Submit");
    } else if (option.equals("Index")) {

      cards.show(student, "student");
    }
  }