views:

531

answers:

1

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.

+1  A: 

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.

Valentin Jacquemin
I can't call the repaint method after each position change because the move code is handled by another class. Anyway it isn't a matter of repaint not getting called because it is. It just wont call paint until the image is done moving.
Nagrom_17
Show your code it will be simpler to help you.
Valentin Jacquemin