add timer on panel......

62 views
Skip to first unread message

Harshal Patil

unread,
May 29, 2012, 7:59:43 AM5/29/12
to google-we...@googlegroups.com
Hello

Can anyone plz help me to create timer and how to add it on the panel?

Joseph Lust

unread,
May 30, 2012, 4:13:54 PM5/30/12
to google-we...@googlegroups.com
Harshal,

Why do you need to add the timer to a panel? What do you want the timer to do? It is not clear from your question.

Timer timer = new Timer();



Sincerely,
Joseph

Harshal Patil

unread,
May 31, 2012, 6:56:21 AM5/31/12
to google-we...@googlegroups.com
Hi Joseph,

I am creating online exam portal.

In that i have to specify some time e.g 1 hour to end the exam.

also it will automatically decrements the time in the 1 second of interval i.e. 1:00 hr, 00:59 hr, 00:57-----------------------------------------00:00 hr.

so it will automatically ends the exam after 1 hour of interval. 

I have to show that decrementing timer on the panel. 

Joseph Lust

unread,
Jun 1, 2012, 1:25:19 PM6/1/12
to google-we...@googlegroups.com
Harshal,

You will need to write a simple stopwatch state machine. You can wrap it up as a simple widget to display the time. Basically you just need to track the current time and decrement it every second.

This has been discussed before on StackOverflow here. See the use the GWT Timer in the bottom answer. You'll also want to have some functions to convert seconds to formatted time to display it in your widget. You could use some GWT formatters on the Date object, or just write your own functions since the math is simple.

You'll want to check on the start time/ elapsed time on the server side too since a mildly talented use could hack the browser side timer. The possible trouble point here is that there is no guarantee that your timer and the serverside will match, since JS could lose time if there was contention for the browser thread, and neither side is an RTC. The last thing you'd want is for someone to finish in time, but get rejected by the server when submitted because they were overtime.

Sincerely,
Joseph

Ben Klein

unread,
Jun 4, 2012, 6:23:42 PM6/4/12
to google-we...@googlegroups.com
If I recall correctly, System.currentTimeMillis() still works in GWT. In your timer code, this can be called; end_time + start_time - current_time will give you how much time is left.
Reply all
Reply to author
Forward
0 new messages