gpt4 book ai didi

java - 每秒而不是立即执行和显示图形

转载 作者:太空宇宙 更新时间:2023-11-04 07:48:59 25 4
gpt4 key购买 nike

我正在使用 jLabels 来模拟生物体的生长。但是,当我实现 for 循环和计时器来尝试显示它移动时,它会卡住,然后显示标签的最终位置,而不是显示它移动。谁能向我解释一下为什么会发生这种情况?

public class TestView extends FrameView {
public TestView(SingleFrameApplication app) {
super(app);
initComponents();
picture = new JLabel();
picture.setIcon(new ImageIcon(System.getProperty("user.dir") +
File.separator + "mouse.gif"));
picture.setBounds(0, 0, 100, 100);
mainPanel.add(picture);

for (int x = 0; x < 20; x++) {
move();
wait(50);
}
}

public static void wait(int n) {
long t0, t1;
t0 = System.currentTimeMillis();
do {
t1 = System.currentTimeMillis();
} while (t1 - t0 < n);
}

public static void move() {
picture.setBounds(picture.getX() + 5, picture.getY(), 100, 100);
}

最佳答案

您可能喜欢这个 diffusion limited aggregation 的示例及其他simulations .

关于java - 每秒而不是立即执行和显示图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14824471/

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