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:
-
Create a new instance of Time. In this case
CalendarTime
is used. Set the time interval. -
Create a new instance of Timer. In this case
AutoTimer
is used. -
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. - 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:
-
Date:
"01.01.00" a simple date of the format: "dd.mm.yy". -
Step:
"26" a Long value is used to represent the time. -
CalendarTime:
"Sat Jul 20 15:38:53 CEST 2002" a time which is represented as a Gregorian Calendar.
Used classes:
Related topics:
ToDo:
-
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:
-
StepTimer:
very simple implementation, is increased manually bygoAhead()
method. -
AutoTimer:
special step timer which inceases automatically with a certain time delay.
Used classes:
Related topics:
ToDo:
-
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:
Application Architecture: Processes | Data Management: Catalog |