Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing repaint() in a loop with a delay 1

Status
Not open for further replies.

TCaldwell

Programmer
Apr 30, 2006
1
US
Hi all,
I am writing a game for my first java program. I want to paint each time a loop executes with a small delay in between to create a cascade effect on screen. I believe that the effeciency routines in the system are collapsing the calls to repaint() into a single call. At any rate, the changes all occur at once after the total delay. Is there some way to force the system to repaint immediately and then delay on each iteration of the loop?

Here is the loop code:
Code:
for (row=row;row<gridRows-1;row++) { 
  if (row == gridRows - 1 || col == 0) break; 
  if (tiles[row+1][col-1] == null) break; 
  Tile14.move(tiles[row+1][col-1],tiles[row][col]); 
  repaint(); 
  try { 
    Thread.sleep(200); 
  } 
  catch (InterruptedException e) {} 
  col--; 
} 
Tile14.move(holdTile,tiles[row][col]); 
repaint();
Any suggestions would be appreciated.
 
Is the loop in a separate thread? If not, I suggest you move it into one. If the loop is in the same thread as the gui (buttons and keyboard polling, etc), the paint will not occur until the end of the loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top