0

coding a tetris-y puzzle game. still just trying to make a skeleton of the game. single blocks "fall" from the top of the screen in the form of colored buttons. when the first block appears it's supposed to color the top left button red, pause, and then color the button in the next column.

int counter = 0;
while (checkLoss(counter)) {
blocks[counter].setFalling();
counter++;
if (counter == 10)
counter = 0;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
//fall();

ignoring the fall method for now starting this method slowly changes the color of all the top row buttons to red and then since the top space is occupied when it starts over it counts as a loss and terminates. Problem is the color of the buttons on the panel don't change until the entire process is done. I've tried repaint/revalidate and neither worked. I'm assuming my infinite loop is the problem but I dunno, do I need to be running this as a seperate thread?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Michael Groleau
  • 81
  • 1
  • 2
  • 9
  • 2
    Do not `sleep()` on the [event dispatch thread](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html); see [*Worker Threads and SwingWorker*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html). – trashgod Feb 07 '13 at 07:58
  • Everyone else that makes a Tetris like game draws the shapes on a canvas (JPanel). You're going to have a hard time managing all of those JButtons. – Gilbert Le Blanc Feb 07 '13 at 14:14

0 Answers0