Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need advice on how writing a program involving time.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
<br>&nbsp;I intend to write a program in Java which simulates a burglar alarm<br>&nbsp;system. This is a quick description of what I require:<br>&nbsp;<br>&nbsp;After entering the correct code in an input box this starts a timer.&nbsp;&nbsp;I will<br>&nbsp;have various pictures (gif's) displayed in the GUI (ie. various detectors<br>&nbsp;represented as doors, windows.) which are clickable.&nbsp;&nbsp;Clicking of these<br>&nbsp;pictures will either open/close these detectors.&nbsp;&nbsp;Depending on whether the<br>&nbsp;time has elapsed this will determine whether the bell will start ringing.<br>&nbsp;(The simulation of the bell could be a pop-up box alerting the user that the bell<br>&nbsp;is on or just a text displayed in the GUI as a label).&nbsp;&nbsp;Entering of the correct<br>&nbsp;code in the input box will stop the bell from ringing but if no code is<br>&nbsp;entered then I need some sort of timer that will keep count for upto 5 minutes and<br>&nbsp;if 5 minutes has elapsed then the bell should stop ringing automatically (ie. An<br>&nbsp;appropriate message should be displayed).&nbsp;&nbsp;Just want to know whether there<br>&nbsp;is a timer object in Java that will keep count of the time for me , what<br>&nbsp;classes will a need to consider.&nbsp;&nbsp;I have some basic knowledge of Swing.<br>&nbsp;&nbsp;Any guidelines on how to begin is strongly appreciated.<br>&nbsp;<br>&nbsp;Many thanks for any help in advance.<br>&nbsp;<br>¦
 
The short answer is to start a thread that sleeps for 5 minutes and then calls a method back on your main program. I use a publish-subscribe relationship rather than a direct callback in places like this, so any number of interested objects could listen to the timer.&nbsp;&nbsp;You could make your timer thread as rich as you need, maybe fire a progress message every second so you could display a count-down clock.
 
There is a class called javax.swing.Timer<br>which basically does what jstandley1 says put sun has already made one for you, <br>take a look at <br><A HREF=" TARGET="_new"> luck <p>ackka<br><a href=mailto:tmoses@iname.com>tmoses@iname.com</a><br><a href= my site</a><br>"Do No Harm, Leave No Tracks"<br>
ICMP Summer 2000, 2600 Article<br>
<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top