java - Displaying JLabel movement -
i attempting create simple animation in series of bubble rotate around centre point. have 1 version of animation bubbles spread centrepoint before begin rotate, works fine, click 1 of images (which sparks animation) screen freezes moment , bubbles appear in end position, rather showing each step made.
what have far is:
while(bubble[1].getdegree() != 270) { long time = system.currenttimemillis(); //the below if statement contains function calls //the rotating bubble animations. next(); draw(); // delay each frame - time took 1 frame time = (1000 / fps) - (system.currenttimemillis() - time); if (time > 0) { try { thread.sleep(time); } catch(exception e){} } } public void draw() { for(int = 1; < bubble.length; i++) { iconlabel[i].setlocation(bubble[i].getx(), bubble[i].gety()); textlabel[i].setlocation((bubble[i].getx()+10),(bubble[i].gety()+10)); } }
for clarity, method "next()" merely changes position of bubble appropriate place, know functioning have had animation work before once implemented animation jlabels stopped working.
any appreciated.
the drawing frozen because block event dispatch thread. drawing done in same thread while
loop, , since loop prevents else happening while it's running, swing can drawing after loop finished, last position drawn.
use swing timer instead:
timer = new timer(delay, new actionlistener() { public void actionperformed(actionevent e) { // whatever need animation updatepositions(); repaint(); } }); timer.start();
and call timer.stop()
when frames need have been processed.
Comments
Post a Comment