Any ideas on how to use the Timer class? As far as i understand it you are supposed to create a class that subclasses the abstract TimerTask class to implement the run() method and pass an instance of that class to the Timer constructor plus two long values denoting the delay time and the period. For some reason the Timer constructor dosent want to take thisAny ideas why?
Also there are no methods within the Timer class that return the number of milliseconds that have elapsed. So how would i get this value? I thought about using the System.current.TimeMillis() but wouldn't that just give me the time in milliseconds that have passed from midnight GMT, Janurary 1, 1970?
Code:class TimeTracker extends TimerTask{ private Timer timer; private TimeTrackerTest tt; private Long l; private long millis; Object[] o; public TimeTracker(TimeTrackerTest tt){ this.tt = tt; timer = new Timer(this,0l,1000l); } public void run(){ try{ millis = scheduledExecutionTime(); l = new Long(millis); o[0] = l; tt.jtf.setText(MessageFormat.format("{0}",o)); }catch(Exception e){System.err.println(e);} } }




Any ideas why?
Reply With Quote