开发者

Java replacing an Icon Image after X time passes

IN SHORT: I want to execute a new command 3 sec after the former command had been issued.

THE STORY: I have an action button that once pressed sets (replaces) an Icon Image (an animaition) on one of the Jlabels.

JLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iamg/slash.gif")));

All I want is to replace the Icon back to the former one after X time passes. In other words I want the new animaition to finish (which is about 4 sec long) and after those 4 sec pass I could set a new Icon.

I realize this can be done with threads unforutly I have no idea how, since all I know is stopping the whole program using something like t开发者_JS百科his:

try
{
    Thread.sleep(3000);      
}
catch (InterruptedException ex)
{

}

Which is stopping the animation it self as well, instead of waiting till 3 sec pass before executing the new command.. Help please?


You should use a Timer. See this tutorial for how to use them. Basically you need to add an action listener to the timer, so that when it fires you can replace the icon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜