0

I'm having a problem with updating the screen in this game of Pong here. The run() method draws shapes to a graphics (myBuffer), which is then drawn to a bufferedImage (myImage). I'm implementing a run() method for Threads so that the paddles can move at the same time.

I know that the other classes (ball, bumper1, bumper2) work in this program because I've made Pong using the same commands in this file, but without a run() method. I used a listener in the previous one, and it updated and refreshed fine (just had an annoyance with the paddle keys interfering with each other! :/)

My guess is that either 1) the thread doesn't execute (unlikely, but unsure) or 2) the way I use the repaint() doesn't work in the thread or 3) I'm missing something obvious. :}

Zchpyvr
  • 1,119
  • 3
  • 12
  • 26

1 Answers1

0

A thread executes the run() method only once. To execute a block repeatedly you can use an infinite loop:

public void run() {
    for (;;) {
        // your code
    }
}
Joni
  • 108,737
  • 14
  • 143
  • 193
  • This was exactly I needed! Instead of a for loop, I put a while loop and it worked fine. Thank you. – Zchpyvr Apr 19 '12 at 00:23