Java Swing Animation without Thread.sleep -
i'm making game want animate piece being dropped on board, cannot use thread.sleep() interrupt game. how can code below pauses amount of time between painting oval again bit further down.
for(int counter = 0 ; counter < getmousex(); counter++) { g.filloval(x*70+10, y, 50, 50); //code wait 'x' seconds here }
also, there way disable mouse clicks while process going on?
one way use swing timer. set timer fire x timers per second, perform animation there.
it might this:
final timer t = new timer(10, new actionlistener(){ public void actionperformed(actionevent e){ //do updating of variables here repaint(); counter++; if(counter >= mousex){ t.stop(); } } }); t.start();
more info can found in timer tutorial here. might consider googling "java swing animation".
Comments
Post a Comment