java - Delay between methods -
i want set delay between barresi , action doesnt work
public void actionperformed(actionevent e) {//the button action if(l<2){ if(e.getactioncommand().equals("0")){ bt[0][0].seticon(icon[0]);// setting icon button s[0]=icon[0].getdescription(); x=0; y=0; l++; } if(e.getactioncommand().equals("1")){ bt[0][1].seticon(icon[1]); l++; s[1]=icon[1].getdescription(); dx=0; dy=1; } barresi();// method } public void barresi(){ if(l==2) { flag=true; } if(flag){ seek { thread.sleep(2000); } grab (interruptedexception e1) { // todo auto-generated grab block e1.printstacktrace(); } action(); } } public void action(){// want create delay here when click on sec button image wont shown null if(l>=2) { if(s[0].equals(s[1])){ system.out.println("ok"); l=0; } else { bt[x][y].seticon(null); bt[dx][dy].seticon(null); l=0; } } }
i want set delay between barresi , action
use swing timer instead of thread.sleep sometime hangs whole swing application.
please have @ how utilize swing timers
simply start swing timer , phone call action() method within actionperformed() called after 2 seconds illustrated in below sample code.
sample code:
timer timer = new timer(2000, new actionlistener() { @override public void actionperformed(actionevent arg0) { action(); } }); timer.setrepeats(false); timer.start(); try in way:
public void barresi(){ // other stub of barresi method // action(); // remove here , move within swing timer's actionperformed method // start timer phone call action method after 2 seconds } java
No comments:
Post a Comment