我有一個Image
名爲worldImageToUse
,我有一個Timer
,它應該在每兩秒之間在兩幅圖像之間切換worldImageToUse
。但它似乎並不奏效。請幫助?Java定時器不工作
public void startWorldImageFlash() {
worldImageFlashTimer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
if(worldImageToUse == worldImage) setWorldImageBW();
if(worldImageToUse == worldImageBW) setWorldImageColor();
}
};
worldImageFlashTimer.scheduleAtFixedRate(task, 0, 1000);
}
public void stopWorldImageFlash() {
worldImageFlashTimer.cancel();
setWorldImageColor();
}