2009-05-30 12 views
2

キューシミュレーションを開発しています。スイングタイマーを使用して一定時間後にオブジェクトをデキューします。インターバルは、キュー内の次のオブジェクトを見て、整数を取得し、対応するタイマーの遅延を設定することによって決定されます。ランタイム中にスイングタイマーの遅延を変更する

はここでプログラムから関連するスニペットです(注:_SECONDS_PER_ITEM2000に別の場所で定義された定数である):

// stop the timer 
qTimer[q].stop(); 

// peek at how many items the customer has, and set the delay. 
qTimer[q].setDelay(customerQueue[q].peek().getItems()*_SECONDS_PER_ITEM); 

// the next time around, this method will see the flag, and dequeue the customer. 
working[q] = true; 

// denote that the customer is active on the UI. 
lblCustomer[q][0].setBorder(new LineBorder(Color.RED, 2)); 

// start the timer. 
qTimer[q].start(); 

私が持っている問題はすべての顧客には、どんなに多くの彼らが持っているアイテム、処理されないことです1秒で

遅延を設定するために使用する必要がある他の方法や手法はありますか?

答えて

3

タイマーを設定すると、次のイベントを発生させるのに使用される遅延が初期遅延になるようです。したがって、上記の例で使用する正しい方法は、setInitialDelay()

{ 
// stop the timer 
qTimer[q].stop(); 

// peek at how many items the customer has, and set the delay. 
qTimer[q].setInitialDelay(customerQueue[q].peek().getItems()*_SECONDS_PER_ITEM); 

// the next time around, this method will see the flag, and dequeue the customer. 
working[q] = true; 

// denote that the customer is active on the UI. 
lblCustomer[q][0].setBorder(new LineBorder(Color.RED, 2)); 

// start the timer. 
qTimer[q].start(); 

} 
です。
関連する問題