2016-05-10 178 views
0

我有一个JTable列表,它显示了一组问题。每个问题都有一个难度级别,我想在JTable中获取简单,中等,难度较大的问题。 This is my interface如何从列表中获取属性

public void actionPerformed(ActionEvent arg0) { 
      Test test= new Test(); 
      Integer id=GestionTestDelegate.doGetLastInsertId(); 
      test=GestionTestDelegate.doFindTestById(id); 
      Integer facile = null; 
      Question question=new Question(); 
      if(questions2.contains(question.getNiveauDeDifficulte().equals("Facile"))){ 
       facile++; 
      }  
      test.setNbrQuestionFacile(facile); 

     GestionTestDelegate.doUpdateTest(test); 

     } 

我试过这段代码,但没有奏效。

回答

1

我试过这段代码,但没有奏效。

那么您发布的代码对我们来说绝对没有任何意义。这是所有定制类的自定义代码。我们不知道“测试”或“问题”是什么,我们不知道你的方法是做什么的。

我想在JTable中获取简单,中等难度的问题。

然后,你需要访问JTable的TableModel的和读取数据的每一行:

TableModel model = table.getModel(); 
int easyQuestions = 0; 

for (int i = 0; i < model.getRoWCount(); i++) 
{ 
    String level = (String)model.getValueAt(i, 2); 

    if ("Easy".equals(level)) 
     easyQuestion++; 

    // repeat for medium and difficult 
} 

System.out.println(easyQuestions);