所以这是我的学校作业For循环输出在jframe
编写一个程序: 接受输入的起始值。 接受输入的结束值。 显示这两个值之间的所有整数(包含)。 提示:使用for循环,不要忘记将输入从字符串转换为整数。
它写在一个jFrame中,它只输出最后一个值,而不是起始值和结束值之间的所有值。我正在使用NetBeans IDE 8.0。
//Variables
int starting, ending;
starting=Integer.parseInt(this.txtStarting.getText());
ending=Integer.parseInt(this.txtEnding.getText());
//for Loop
for(int output=starting; output < ending; output++) {
String out1 = Integer.toString(output);
this.lblValues.setText(out1);
}
我不确定发生了什么问题。当我System.out.println(output);
它输出我想要的东西。
'setText'方法设置文本。它不附加到现有文本。 – Kayaman
将它写出到JTextArea,通过'myTextArea.append(out1 +“\ n”)去追加文本;' –
如何将正确的文本添加到jLabel? – sadsalad