使用Java Mysql并没有减少单选按钮未选中标记

我正在用Java和mysql创建一个简单的考试系统。当我开始考试时,从数据库中成功显示的所有问题,如果我阅读并回答了问题,然后单击“下一步”按钮,它将移至下一个问题。一切正常。如果正确单击了答案,则添加的标记为1.除非未选中,否则答案将变为0。我的问题是,如果我单击单选按钮上的正确答案,标记更改为1。再次选择相同的问题作为错误答案,它没有更改为0,但仍标记为1。如何解决该问题我清除了不会清除的单选按钮。到目前为止我尝试过的东西附在下面。

Click Correct answer . mark displayed 1 correctly enter image description here

相同的问题答案之后变成错误的答案。分数显示1.i如果我们选择错误的答案,第二次分数递减时需要显示。我需要更改为1变为0

enter image description here

编码到目前为止到目前为止我尝试过的内容。 点击答案

public void answercheck()
   { 
       String studentanswer="";
       if(r1.isSelected())
       {    
      if(r1.isSelected() == true)
       {
           studentanswer = r1.getText();
           r2.setSelected(false);
           r3.setSelected(false);
           r4.setSelected(false);
       }
        else
       {
           studentanswer="";
           r1.setSelected(false);
            r2.setSelected(true);
           r3.setSelected(true);
           r4.setSelected(true);
       }
       }

       else  if(r2.isSelected())
       {
        if(r2.isSelected() == true)
       {
           studentanswer = r2.getText();

           r1.setSelected(false);
           r3.setSelected(false);
           r4.setSelected(false);
       }

            else
       {
           studentanswer="";
           r2.setSelected(false);
           r1.setSelected(true);
           r3.setSelected(true);
           r4.setSelected(true);
       }
   }

       else  if(r3.isSelected())
       {
          if(r3.isSelected() == true)
          {
           studentanswer = r3.getText();
            r1.setSelected(false);
           r2.setSelected(false);
           r4.setSelected(false);
          }
          else
          {
                 studentanswer="";
                r3.setSelected(false);
                r1.setSelected(true);
                r2.setSelected(true);
                r4.setSelected(true);
          }
       }


      else  if(r4.isSelected())
       {
          if(r4.isSelected() == true)
          {
           studentanswer = r4.getText();
            r1.setSelected(false);
           r2.setSelected(false);
           r4.setSelected(false);
          }
          else
          {
                 studentanswer="";
                r4.setSelected(false);
                r1.setSelected(true);
                r2.setSelected(true);
                r4.setSelected(true);
          }
       }
      if(studentanswer.equals(answer))
       {

           marks = marks + 1;
           String marks1 = String.valueOf(marks);
           txtc.setText(marks1);

       }

 }

从数据库加载所有问题

   public void Connection()
   {

        try {
             Class.forName("com.mysql.jdbc.Driver");
             con = DriverManager.getConnection("jdbc:mysql://localhost/onlineex","root","");
             stat = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
             rs = stat.executeQuery("select id,question,option1,option2,option3,option4,answer from questions order by id DESC");

              while(rs.next())
            {     
                txtqu.setText(rs.getString("id"));
                txtques.setText(rs.getString("question"));
                r1.setText(rs.getString(3));
                r2.setText(rs.getString(4));
                r3.setText(rs.getString(5));
                r4.setText(rs.getString(6));
                 answer = rs.getString(7);
            }


        } catch (ClassNotFoundException ex) {

        } catch (SQLException ex) {

        }

   }

下一步按钮

if(!rs.isFirst())
            {

            rs.previous();
             txtqu.setText(rs.getString("id"));
            txtques.setText(rs.getString("question"));
            r1.setText(rs.getString(3));
            r2.setText(rs.getString(4));
            r3.setText(rs.getString(5));
            r4.setText(rs.getString(6));
            answer = rs.getString(7);
            answercheck();
            }   

上一个点击按钮

if(!rs.isLast())
            {
                rs.next();
                txtqu.setText(rs.getString("id"));
                txtques.setText(rs.getString("question"));
                r1.setText(rs.getString(3));
                r2.setText(rs.getString(4));
                r3.setText(rs.getString(5));
                r4.setText(rs.getString(6));
                answer = rs.getString(7);

            }
评论