简体   繁体   English

延迟for循环,直到任务完成

[英]Delaying a for loop until the task is completed

I want to make a for loop wait until my other desired task is performed. 我想进行一个for循环,直到执行我的其他所需任务为止。 In my case i want to validate a component within a loop and then increment the counter... 就我而言,我想验证循环中的组件,然后增加计数器...

for(int i = 1; i<=56; i++)
    {
      jl.setIcon(new ImageIcon(ImageIO.read(new File("C:\\``Documents and Settings\\Prasad\\My Documents\\My Pictures\\"+Integer.toString(i)+".png"))));
      jl.revalidate();
    }

so here I want to open the images and validate the JLabel every time the loop runs. 所以在这里我想每次循环运行时打开图像并验证JLabel。 What happens is the images are loaded but the one displayed is only the last one. 发生的是加载了图像,但显示的只是最后一张。 ie "56.png" the others are not!!! 即“ 56.png”,其他都不是!

So is there any solution to this?? 那么有什么解决办法吗? Please help me!! 请帮我!! All help is appreciated... 感谢所有帮助...

When you load an Image, you can attach an ImageObserver to that image to be notified when various stages in the loading have happened. 加载图像时,可以将ImageObserver附加到该图像,以在加载的各个阶段发生时得到通知。 For more detailed information, look at this tutorial . 有关更多详细信息,请参阅本教程

If you're running loops in your GUI code, you're almost certainly doing something wrong. 如果您在GUI代码中运行循环,则几乎可以肯定您做错了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM