Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 如何设置jLabel以输出多个循环_Loops_Label - Fatal编程技术网

Loops 如何设置jLabel以输出多个循环

Loops 如何设置jLabel以输出多个循环,loops,label,Loops,Label,我正在做家庭作业,这要求我做一个重要的程序。给出的例子是 int i = 1; while (i <= 5){ System.out.println(i); i++; } 现在,我所有的东西都在工作,除了我需要将输出分配给一个标签,我所拥有的是 while (start <= end) { outputLabel.setText(String.valueOf(start)); start++; } } 当我运行它时,它只

我正在做家庭作业,这要求我做一个重要的程序。给出的例子是

int i = 1;
while (i <= 5){
     System.out.println(i);
     i++;
}
现在,我所有的东西都在工作,除了我需要将输出分配给一个标签,我所拥有的是

while (start <= end) {
        outputLabel.setText(String.valueOf(start));
        start++;
    }
}

当我运行它时,它只显示结束编号。我想这是因为标签每次循环时都会重置,而不是显示所有循环。如何使其显示每个数字而不是最后一个数字?

您需要将数字添加到标签文本中:

outputLabel.setText(outputLabel.getText() + start);
System.out.println对我来说毫无意义