import java.util.Date;
import java.io.*;

public class TimerUser implements TimerListener
{
    public TimerUser(int time)
    {
	myTimer = new Timer(time,this);
	myTimer.start();
	myRunning = true;
	stuff();
    }

    public void stuff()
    {
	BufferedReader reader = new BufferedReader(new
	    InputStreamReader(System.in));

	String s=null;
	int count = 0;
	
	while (true) {
	    try {
		if (reader.ready()) {
		    s = reader.readLine();
		    count++;
		    log(count + "\t" + s);
		}
	    }
	    catch (IOException ioe){ }

	    if (! myRunning) {
		break;
	    }
	    try{
		Thread.sleep(50);		    
	    }
	    catch (InterruptedException ioe) { }
	}
    }

    public void timerStarted(Timer timer)
    {
	log("started "+timer.timeRemaining());
	myRunning = true;
    }
    
    public void timerStopped(Timer timer)
    {
	myRunning = false;
	log("stopped "+timer.timeRemaining());
    }

    public void timerTicked(Timer timer)
    {
	log ("ticking "+timer.timeRemaining());
    }

    protected void log(String s)
    {
	System.out.println(s);
    }

    Timer myTimer;
    private boolean myRunning;
    
    public static void main(String args[])
    {
	int time = 10;
	if (args.length > 0) {
	    time = Integer.parseInt(args[0]);	    
	}
	TimerUser tu = new TimerUser(time);
    }
}
