gpt4 book ai didi

java - 用于绘制圆的 While 循环

转载 作者:行者123 更新时间:2023-12-01 18:35:48 25 4
gpt4 key购买 nike

到目前为止,这是我的代码,我之前使用相同的代码创建了一个 for 循环来创建 100 个随机圆圈,但现在我需要使用 while 语句,并且对使用哪些整数和不使用哪些整数有点困惑。我编译它没有任何错误,但是当它运行时,弹出的窗口中没有任何内容......

public void paintComponent(Graphics g) {
super.paintComponent(g);

Dimension d = getSize();
{
int i = 0;
while (i<=100)
{
Color color = new Color(generator.nextInt(255),
generator.nextInt(255), generator.nextInt(255));
g.setColor(color);

int circleSize = generator.nextInt(d.width / 4);
int x = generator.nextInt(d.width - circleSize);
int y = generator.nextInt(d.height - circleSize);
g.fillOval(x, y, circleSize, circleSize);
g.drawArc(x, y, circleSize, circleSize, 0, 360);
}
}

最佳答案

你正处于无限循环中。您没有增加i。将 i++; 添加到循环底部,循环至少应该终止。

关于java - 用于绘制圆的 While 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22080190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com