HowTo's - Application Architecture: Time Management

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.
Time management in SalesPoint Framework is abutted on several Java classes:
java.util.Calendar
java.util.GregorianCalendar
java.util.Timer
java.util.TimerTask
java.util.TimeZone
java.sql.TimeStamp

Used classes:

Related topics:

ToDo:

  1. Create a new instance of Time. In this case CalendarTime is used. Set the time interval.
  2. Create a new instance of Timer. In this case AutoTimer is used.
  3. If you need, add a TimerListener and add the methods the class must inherit from the base class.
    Add your code to react to the events.
  4. Finally start the timer.

Example Source Code:

1
        // initialize with current system time and increase time by second
        CalendarTime calendarTime = new CalendarTime();
        calendarTime.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 autoTimer = new AutoTimer(calendarTime, (long) 992);
			
        3
        // if it becomes more complicate it will be clearer to realize 
        a subclass of TimerAdapter or to implement TimerListener
        autoTimer.addTimerListener(new TimerListener()
                {
                    public void onGoneAhead(TimerEvent timerEvent)
                    {
                        System.out.println(timerEvent.getTime());
                    }

                    public void onTimeSet(TimerEvent timerEvent)
                    {

                    }

                    public void onIntervalSet(TimerEvent timerEvent)
                    {

                    }
                });
        4
        // start the timer
        autoTimer.start();
		

Back to:


Select a time type

Description:
A Time Object is used by the Timer. It gives the Timer it´s certain shape.
The Time Object defines which time field will be increased by goAhead method of the Timer.
Choose the following timer types:

Used classes:

Related topics:

ToDo:

  1. Create a new instance of Time. In this case CalendarTime is used. Set the time interval.

Example Source Code:

1
        // initialize with current system time and increase time by second
        CalendarTime calendarTime = new CalendarTime();
        calendarTime.setTimeToCount(CalendarTime.SECOND);
		

Back to:


Select a timer type

Description:
A Timer is able to manage the current time in your application.
It is referenced to a Time which gives the Timer it´s shape.
Choose of following Timer types:

Used classes:

Related topics:

ToDo:

  1. Create a new instance of Timer. In this case AutoTimer is used.

Example Source Code:

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

Back to:


previous Application Architecture: ProcessesData Management: Catalog next


Valid HTML 4.01!