Timer läuft ab
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@106 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
4870017d27
commit
614d0935be
2 changed files with 46 additions and 2 deletions
|
@ -1,5 +1,47 @@
|
|||
package jrummikub.control;
|
||||
|
||||
public class TurnTimer {
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
public class TurnTimer implements ActionListener {
|
||||
private IView view;
|
||||
private int timeLeft = 60;
|
||||
private Timer timer;
|
||||
private Event timeRunOutEvent = new Event();
|
||||
|
||||
public TurnTimer(IView view) {
|
||||
this.view = view;
|
||||
timer = new Timer(1000, this);
|
||||
timer.setRepeats(true);
|
||||
timer.setCoalesce(false);
|
||||
view.getPlayerPanel().setTimeLeft(timeLeft);
|
||||
}
|
||||
|
||||
public void startTimer() {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
public void stopTimer() {
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
timeLeft--;
|
||||
view.getPlayerPanel().setTimeLeft(timeLeft);
|
||||
if (timeLeft == 0) {
|
||||
timer.stop();
|
||||
timeRunOutEvent.emit();
|
||||
}
|
||||
}
|
||||
|
||||
public IEvent getTimeRunOutEvent() {
|
||||
return timeRunOutEvent;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue