Delays during tepainting

hi have have a problem i have this topic could be posted here or in GUI swing but seems and the thing i am developing is a game i though you all would have had the same problem how do i pause ie have a delay before repaint when somthing is in a loop like

for (int i=0<10;i++)

{

status="asldfj "+i; //changed the satus of the game or what ever calculations need to be done.

repaint(); //draw tell that the screen needs to be repainted

//PUT DELAY HERE.

//so that i can see the changes to the things on the screen.

}

what seems to happen if i use Thread.sleep it paints waits the combined total of the all the delays in the loop and then paints screen the the last value of status.

need help can anyone help me

thanks

nibur

[799 byte] By [Nibur] at [2007-9-30 22:50:21]
# 1
where is this block of code? You need it on a separate thread from the event dispatch thread so the repaint can do its job without being asked to sleep. In other words, try to keep this block out of event listeners and paint methods. See if that helps at all.
jboeing at 2007-7-7 13:24:34 > top of Java-index,Other Topics,Java Game Development...
# 2

I think what you're asking to do is what we call Active Rendering. If you're in an Applet, I recommend overriding the update() and paint() methods to do nothing. This will make it so that the Applet does NOT render whenever it wants to, and instead you can make the game render only when YOU want it to. That's the key to having a constant framerate. Instead, write your own method that draws all of your stuff onto the Applet.getGraphics() context. If you're using a Frame, you can get double buffering automatically. Otherwise you'll want to do some searching of the forums to see what double buffering is and how you can manage it yourself. If you don't want to mess with all that, just go and slap this code in there and see what happens :) The AdvancedTimer Class needs to be downloaded with the GAGETimer library at http://java.dnsalias.com/

Good luck!

at = new AdvancedTimer();

tick = 0;

at.start();

int fps = 50; //this is a very good choice because it's easy to maintain even with poor resolution timers

long ticksPerFrame = AdvancedTimer.getTicksPerSecond()/fps;

while (gameIsRunning) {

movePiecesAndDoLogic();

paintYourStuff();

//here's where we delay!

at.sleepUntil(tick += ticksPerFrame);

}

Malohkan at 2007-7-7 13:24:34 > top of Java-index,Other Topics,Java Game Development...