2016-05-10 174 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);