I am writing an application to put a basketball scoreboard on a big screen TV. I am having a little trouble with the clock. I have written a count down timer that works fine but I can't stop the count if a team takes a time out. Can someone help me with the code that will allow me to start and stop the clock. I have a socket for communicating between two computers, one is attached to the big TV and the other is the machine use to control the scoreboard machine. I connect through a socket and send commands to the scoreboard machine like "startClock" to start it and I would like to sent "stopClock" to stop it and then "startClock" once again to resume. I have the communications working fine and when I send "startClock" to the scoreboard machine the clock starts as it should. Any ideas how to toggle it on and off. The timer code is below and I start it with:
CountDownTimer c = new CountDownTimer(0, 8, 0);
It starts counting down from 8 minutes;
Thanks.
public class CountDownTimer implements ActionListener {
private long count;
private DateFormat df;
private javax.swing.Timer t;
public CountDownTimer(int hours, int minutes, int seconds) {
// suppose to show as in 01 HR 30 MIN 30 SEC.
count = 0;
t = new javax.swing.Timer(1000, this);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hours);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.SECOND, seconds);
count = cal.getTime().getTime();
df = new SimpleDateFormat("mm:ss");
t.start();
}
public void actionPerformed(ActionEvent e) {
// suppose to countdown till OO HR 00 MIN 00 SEC
tfTime.setText(df.format(count));
if(df.format(count).equals("00:00:00"))
t.stop();
count -= 1000;
}
}
Open in new window