Reputation: 131
I have a little java applet where I create 2 threads, one thread repaints and the other moves an image from a point to where the user clicks. The problem is that when I call the move function it loops until the image is where the user clicks but it wont repaint until I break out of the loop even though the thread doing the moving and the thread doing the painting are separate.
shortened version of key points:
my program is an applet using the paint() method
I have 2 threads one moves an image and the other paints that image
when I am moving the image it is in a while loop
the painting thread is still calling repaint() but that is as far as the call goes, it never repaints
thank you for your time.
Upvotes: 1
Views: 1232
Reputation: 2265
It might be useful to read an introduction of the painting system of the AWT framework of Java. Take a look for example at th one from Sun: http://java.sun.com/products/jfc/tsc/articles/painting/index.html
In your case you don't need 2 threads. The thread in charge of repainting your applet is created by AWT. It is called the event dispatching thread or EDT. So you just need to change the position of your image and on each change call the repaint method on your applet.
Upvotes: 1