SOURCECODE

How to... incorporate a Timer


Description:
A Timer is able to manage the current time in your application. A Timer needs a Time Object to be referenced on.
If you want to react to different TimerEvents, you will have to incorporate a TimerListener (see listing).

ToDo's:
  1. Make a new instance of Time. (See also: HowTo..select a Time type )
  2. Make a new instance of Timer. (See also: HowTo..select a Timer type )
  3. Eventuelly add TimerListener. ( t.addTimerListener(TimerListener tlListener) )
  4. Start timer. ( t.start() )

Time management in SalesPoint Framework is abutted on several Java classes:
java.util.Calendar, java.util.GregorianCalendar, java.util.Date, java.util.Timer, java.util.TimerTask, java.util.TimeZone
java.sql.Date, java.sql.Time, java.sql.Timestamp

Uses:
Timer  StepTimer  AutoTimer  Time  Date  Step  CalendarTime  TimerListener  TimerAdapter  TimerEvent  



SourceCode

// mainly imports
   import sale.CalendarTime;
   import sale.AutoTimer;
   import sale.events.TimerAdapter;
   import sale.events.TimerEvent;


      //...

       1
      // initialize Time with current system time
         CalendarTime autoCalendarTime = new CalendarTime();

      // AutoTimer will increase time by one sec
         autoCalendarTime.setTimeToCount(CalendarTime.SECOND);

       2
      // initialize Timer with CalendarTime and 992ms delay from step to step
      // (1000ms are too much, because the autotimer is delayed additionally)
         AutoTimer at = new AutoTimer(autoCalendarTime, (long) 992);

       3
      // add a Timer Listener
      // if it becomes more complicate it will be clearer
      // to realize a subclass of TimerAdapter or to implement TimerListener
         at.addTimerListener(
                               new TimerAdapter()
                               {
                               // method called when time has been increased
                                  public void onGoneAhead(TimerEvent tevtEvent)
                                  {
                                     System.out.println(tevtEvent.getTime());
                                  }
                               }
                            );

       4
      // starting timer
         at.start();

      //...