swing - make a special delay in gui of java -
i've made code in java, wanna make delay after part of code, when use delay or sleep codes whole code sleeps delay time wanna see ground changes in gui , make delay!!! should do?(i use swing gui)
for (int = 0; < 8; i++) { (int j = 0; j < 8; j++) { if (matrisbazi[i][j] == 0) { jb[i][j].setbackground(color.white); } if (matrisbazi[i][j] == 1) { jb[i][j].setbackground(color.red); } if (matrisbazi[i][j] == 2) { jb[i][j].setbackground(color.blue); } } } jb[i][j].addactionlistener(new actionlistener() { @override public void actionperformed(actionevent event) { click(s); } }); my actionperformed void called before , inside of click(); functions , doing process how add swing timer code void?! think timer doesn't work until click(); finished.
if swing gui (you don't tell us), you'll not want use thread.sleep(...) sleep swing event thread , put entire application sleep. instead you'll want use swing timer.
note if you'll incrementing variable slowly, you'll not use loop, instead increment variable directly inside of timer's actionperformed method.
for example this:
for (int = 0; < max; i++) { // animation using thread.sleep(sleeptime); } would changed to:
new timer(sleeptime, new actionlistener(){ private int = 0; public void actionperformed(actionevent evt) { if (i >= max) { // stop animation } // animation i++; } }).start();
Comments
Post a Comment