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

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -