Java 如何按难度级别显示所有问题
我有一个JTable,我想根据难度级别显示问题,程序正常执行,但问题是它只显示一个难度级别(难度问题),我想按难度级别查看所有问题?我需要对JTable上的所有IF求和?或者我对是否有问题Java 如何按难度级别显示所有问题,java,swing,jtable,Java,Swing,Jtable,我有一个JTable,我想根据难度级别显示问题,程序正常执行,但问题是它只显示一个难度级别(难度问题),我想按难度级别查看所有问题?我需要对JTable上的所有IF求和?或者我对是否有问题 public void actionPerformed(ActionEvent arg0) { categorie=GestionCategorieDelegate.doFindCategorieById(PreparerTest.idCategorie); S
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();
}
这就是结果
您的问题是由于在每个if块上,您为
问题变量指定了一个新的引用。所以你最后的任务是“困难”的任务。您没有指定对象问题
的类型,但我假设它是列表
或其他集合
类型。请尝试使用Collections.add()
或Collections.addAll()
而不是赋值。您的问题是由于在每个if块上,您为问题
变量指定了一个新的引用。所以你最后的任务是“困难”的任务。您没有指定对象问题
的类型,但我假设它是列表
或其他集合
类型。尝试使用Collections.add()
或Collections.addAll()
列出问题,而不是分配;我必须这么做?问题。添加所有(问题);在所有的如果?我必须请帮助我,我是一个Java和Java的初学者swing@Hovercraft满是鳗鱼,你能帮我吗?嘿,很抱歉回复太晚了,只需提问。addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Facile.getText()),category,“Facile”);列出问题;我必须这样做?questions.addAll(questions);在所有的IF?我必须做什么请帮助我我是Java和swing@Hovercraft满是鳗鱼,你能帮我吗?嘿,很抱歉回复太晚了,只需提问即可。addAll(GestionTestDelegate.doPrepareRandomTest(Integer.parseInt(Facile.getText()),category,“Facile”);