problem with repaint()

Hi,

I have some intereseting problem. These are parts of code

...

while (Thread.currentThread() == animator){

System.out.println("frame = " + frame +" numFrame = " + numFrame);

this.repaint();

System.out.println("frame = " + frame +" numFrame = " + numFrame);

...

publicvoid paint(Graphics g){

super.paint(g);

System.out.println("paint");

...

publicvoid update(Graphics g){

super.update(g);

System.out.println("update");

...

publicvoid setIconAnimation(){

System.out.println("setIconAnimation : numFrame = " + numFrame);

...

and these are console parts

***

frame = 0 numFrame = 7

frame = 0 numFrame = 7

paint

setIconAnimation : numFrame = 7

frame = 1 numFrame = 7

frame = 1 numFrame = 7

paint

setIconAnimation : numFrame = 7

paint

***

run

frame = 0 numFrame = 7

frame = 0 numFrame = 7

frame = 1 numFrame = 7

frame = 1 numFrame = 7

***

Why sometimes it call procedure paint() (or maybe update()), but sometimes not? What can be cause?

Thanks.

[1699 byte] By [boba5555a] at [2007-10-3 4:49:19]
# 1

there is no problem, rather, that's exactly how it is supposed to work.

When you call repaint(), it does not paint immediately. Instead it schedules a paint operation for the event dispatcher thread. The event dispatcher thread simply takes events out of a queue and runs them. So when you call repaint(), a paint event is added to the end of the queue. It may take a long time before the paint event reaches the front of the queue, because all those other events in the queue need to run first.

If you want to run an event from another thread, you can use EventQueue.invokeAndWait(). But just so you know, calling repaint() from inside an invokeAndWait() won't work because repaint() actually schedules the paint event using EventQueue.invokeLater(). So you may need to call paint() or paintComponent() within the invokeAndWait() in order to paint immediately.

jvaudrya at 2007-7-14 22:53:49 > top of Java-index,Desktop,Core GUI APIs...
# 2
In a Swing application there is no need to override the update() method.Also, you should be overriding the paintComponent() method, not the paint() method for custom painting.
camickra at 2007-7-14 22:53:49 > top of Java-index,Desktop,Core GUI APIs...
# 3
@jvaudry I don't understand. Can you give me a simple part of code which will do that? Thanks.Message was edited by: boba5555
boba5555a at 2007-7-14 22:53:49 > top of Java-index,Desktop,Core GUI APIs...