I am wondering how would one change the JLabel icon from one image to another image, and then wait a second and then call a function. I have tried the Thread.sleep
and the Thread.wait
methods along with a timer and could not get it to work. It would not change the icon and would instantly call the function. If you have any suggestions for me that would be appreciated.
try to implement using conditional programming such as at first change icon if icon is changed than only call function otherwise not you can also add these to action listener
you can also try a empty for loop with some sleep and then call for another image and then function or as you like
i guess this is an idea:
JLabel myLabelWithIcon = .....;
new Runnable{
@Override
public void run() {
if(myLabelWithIcon.hasOldImage()){
// do the change here
}
else{ return; }
Thread.sleep(1000); // This code can take current runnable thread
CallAnotherFunction();
}
}.start();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.