if(e.getSource()==continuous)
{
TimerTask task = new TimerTask()
{
public void run()
{
rollthedice();
}
};
timer.schedule(task, java.util.Calendar.getInstance().getTime(), 500);
}
if(e.getSource()==stop)
{
timer.cancel();
}
我按下连续按钮,rollthedice() 每秒执行两次循环,我按下停止按钮 rollthedice() 停止,我一直在寻找的是一种在我按下停止开始循环 rollthedice() 后再次按下连续按钮的方法再次方法,停止是停止rollthedice()的连续循环,但我希望能够再次点击连续按钮,idk怎么做,我一直在寻找
更新的想法:
Runnable runner = new Runnable(){
public void run()
{
rollthedice();
}
}
if(e.getSource()==continuous)
{
future = scheduler.scheduleAtFixedRate(runner, 0, 500, TimeUnit.MILLISECONDS);
}
if(e.getSource()==stop)
{
future .cancel();
}