2016-04-29 33 views
1

我有一個JTable,我想根據難度級別顯示問題,程序正常執行,但問題是它只顯示一個難度級別(難題)我想根據難度級別查看所有問題?我需要總結JTable上的所有IF?或者我對IF有問題?如何根據難度級別顯示所有問題

public void actionPerformed(ActionEvent arg0) { 
      categorie=GestionCategorieDelegate.doFindCategorieById(PreparerTest.idCategorie); 
      System.out.println(categorie); 
      if(Facile.getText().length()!=0) 
      { 
       questions=GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Facile.getText()), categorie,"Facile"); 

      } 
      else 
      { 

      } 
      if(Moyen.getText().length()!=0) 
      { 
       questions=GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Moyen.getText()), categorie, "Moyen"); 

      } 
      else 
      { 

      } 
      if(Difficile.getText().length()!=0) 
      { 
       questions=GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Difficile.getText()), categorie, "Difficile"); 

      } 
      System.out.println(questions); 
      initDataBindings(); 
     } 

這個結果 enter image description here

回答

0

你的問題是由於這樣的事實:在您的每一個if塊,你分配一個新的引用您的questions變量。所以你最後得到了你所做的最後一次分配,即「困難」的分配。你沒有指定什麼類型的對象questions是,但我會認爲它是List或其他一些Collection類型。嘗試使用Collections.add()Collections.addAll(),而不是分配。

+0

列表問題;我必須這樣做? questions.addAll(問題);在所有的IF? – Daly

+0

我必須請幫助我我是一個Java和鞦韆上的初學者 – Daly

+0

@Hovercraft全部的鰻魚你能幫我嗎? – Daly