Friday 15 August 2014

swing - Java Thread.sleep() within a for loop -



swing - Java Thread.sleep() within a for loop -

public void playpanel() throws ioexception{ for(int = 0; i<listdata.size(); i++){ seek { thread.sleep(1000l); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } ascii.settext(listdata.get(i)); } }

what i'm trying play through listdata arraylist type, copied ascii jtextarea. supposed animation, when nail play function displays first slide, waits second, next slide, etc.

when run thing happens pause nil on screen changing until displays final slide. i'm not sure what's wrong it

you should never phone call thread.sleep(...) on swing event thread unless goal set entire application sleep, rendering useless. instead, rid of loop, , "loop" using swing timer. should work, or close functioning solution (caveat: code has not been compiled nor tested):

int delay = 1000; new timer(delay, new actionlistener() { private int = 0; @override public void actionperformed(actionevent e) { if (i < listdata.size()) { ascii.settext(listdata.get(i)); } else { ((timer) e.getsource()).stop(); } i++; } }).start();

java swing timer sleep

No comments:

Post a Comment