如何设置jLabel输出多个循环(How to set jLabel to output multiple loops)

编程入门 行业动态 更新时间:2024-10-18 22:35:33
如何设置jLabel输出多个循环(How to set jLabel to output multiple loops)

我正在做一项家庭作业,这要求我制定一个重要的计划。 给出的例子是

int i = 1; while (i <= 5){ System.out.println(i); i++; }

现在,我有一切工作,除了我需要将输出分配给标签,我有什么。

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

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

I'm working on a homework assignment, which requires me to make a program that counts. The example given is

int i = 1; while (i <= 5){ System.out.println(i); i++; }

Now, I have everything working, except I need to assign the output to a label, what I have is.

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

When I run it, all it displays is the end number. I figure this is because the label is reset every time it loops, instead of displaying all the loops. How can I make it show every number instead of just the last number?

最满意答案

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

outputLabel.setText(outputLabel.getText() + start);

System.out.println对我来说根本没有意义。

You will need to add the number to the text of the label:

outputLabel.setText(outputLabel.getText() + start);

The System.out.println doesn't make sense for me at all.

更多推荐

本文发布于:2023-07-22 09:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何设置   jLabel   set   multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!