2016-05-10 23 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で簡単な、meduim、難しい質問の番号を取得したいと思います。

次にあなたが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); 
関連する問題