I looked for this discussion, but didn't found, so... sorry if repeated!
I have an application that, sometimes, takes so much time for doing things. Then, I'd like to show something like an animated icon to the user while doing the processing. This icon must not hide the program's screen, i want it to be in a layer above.
I have a Canvas class. From the keyPressed method, I call Timer.schedule() for paint the icon's frames in the given period. So, I have the processing, and then Timer.cancel(). Then I call repaint() for have the program back.
My problem is: the calls for repaint() that should draw my icon effectively happen just after the end of keyPressed. In other words, the icon comes and goes fast, and after the end of the processing.
I tried to put a serviceRepaints() after the repaint() in the method run() of the TimerTask. But this way the timer stays blocked in this call until the end of keyPressed! If I call just paint(g), the routine is called, but the effect comes to screen just after the end of keyPressed...
I think maybe the keyPressed method blocks the repaint... but I don't know why...
Someone knows how could I do this?
Thanks so much for the attention!