|
| ||||||||||
| Tags: actionlistener, code, java, milliseconds, timer, util |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Help for Timer examples in Java
Please tell me some information about the examples of timer in Java. Hoping that someone hanging out there will help me soon.!! ![]() |
|
#2
| |||
| |||
| Re: Help for Timer examples in Java
Since, you are new to Java, I think that you should know the basic things that are required for timer examples. When programming you may see the need to perform a task every so often. For example, if you draw a clock on the screen every second we move or repainting the second. Perhaps you want to see when a file is created, which can, for example, every ten seconds to see if it exists. In short, there are plenty of possible applications that you need to perform regular tasks. |
|
#3
| ||||
| ||||
| Re: Help for Timer examples in Java
Java provides two distinct classes that help us to this task. Javax.swing.Timer are classes and java.util.Timer. In both classes we say we notice how often (eg every second notice in the case of clock) and they are responsible for calling a method that we have implemented. The result is that this method (which paints the seconds on the screen), will be called every so often (once per second for the clock). |
|
#4
| ||||
| ||||
| Re: Help for Timer examples in Java
You will have to use the javax.swing.Timer for doing the Timer examples in Java. This class is easier to use. Just instantiate it passing each how long (in milliseconds) we want to let us know and ActionListener, which method actionPerformed () will run periodically. Then just call the method start () when we want the timer starts counting. The code may look like this: Code: Timer timer = new Timer (TimeInMilliseconds, new ActionListener () ( public void actionPerformed (ActionEvent e) ( // Here you have to execute the code. ) )); ... timer.start (); |
|
#5
| |||
| |||
| Re: Help for Timer examples in Java
According to me, you should know more about the java.util.Timer. This class is more general, has more options, but is somewhat more complex to use. To start it you must call either of the schedule (). I will not detail them all because that's what the API, but give us a good chance. We can say things complex, for example, that "as of July 22, 2010, 17:00 begins to notice me every 5 minutes "Or we can say simple things like" tell me once in 5 minutes". |
|
#6
| ||||
| ||||
| Re: Help for Timer examples in Java
Within the repetitive warnings are even two options of the java.util.Timer :
|
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Help for Timer examples in Java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error while using the timer class in Java | ScarFace 01 | Software Development | 4 | 27-07-2010 01:47 AM |
| Timer and alarm in C / Java | Izek | Software Development | 4 | 20-07-2010 03:24 PM |
| Execute timer service in java | Messenger | Software Development | 4 | 20-07-2010 01:27 PM |
| Problem in java timer Class | Gunner 1 | Software Development | 5 | 17-02-2010 11:48 PM |
| Sources of Java Application Examples | Steyn | Software Development | 5 | 09-01-2010 12:51 AM |