Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Help for Timer examples in Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-07-2010
Member
 
Join Date: Apr 2010
Posts: 81
Help for Timer examples in Java
  

Hi everybody. I have recently started studying the Java programming language. I have done very basic coding in Java. Now I am eager to know about the timer in java. Since, I am not having any knowledge about it, I thought that taking suggestions (help) from you guys would be helpful.!! Please tell me some information about the examples of timer in Java. Hoping that someone hanging out there will help me soon.!!

Reply With Quote
  #2  
Old 24-07-2010
Member
 
Join Date: Dec 2008
Posts: 161
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.
Reply With Quote
  #3  
Old 24-07-2010
Member
 
Join Date: Jan 2006
Posts: 211
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).
Reply With Quote
  #4  
Old 24-07-2010
Member
 
Join Date: Jan 2009
Posts: 140
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 ();
Reply With Quote
  #5  
Old 24-07-2010
Member
 
Join Date: Jan 2009
Posts: 143
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".
Reply With Quote
  #6  
Old 24-07-2010
Member
 
Join Date: Mar 2008
Posts: 232
Re: Help for Timer examples in Java

Within the repetitive warnings are even two options of the java.util.Timer :
  • With the methods schedule (), for example, if the notice is repeated every second, it is possible that the computer is busy doing other things, so we can notice a certain delay. This option accumulates the delay between calls. If the computer is very busy and gives us warnings every 1.1 seconds instead of 1, the first notice we received in the second 1.1, the second at 2.2, the third in the 3.3, etc, etc. If we do our clock This way, you have to take advances or delays in no time.
  • The other option is scheduleAtFixedRate methods (). With these methods, the warnings are related to the notice, in this way, if there is delay in the notice, does not affect when the following occurs. As before, if the computer is very busy and gives warnings every 1.1 seconds instead of every second, the first warning will be received in the second 1.1, the second 2.1, third in the 3.1, etc. The delay is not being collected. It is clear that to make a clock, as in our example, we use the second form (scheduleAtFixedRate methods () instead of schedule ()).
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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
Java - System Tray with timer Anthony12 Software Development 4 20-07-2010 11:58 AM
Sources of Java Application Examples Steyn Software Development 5 09-01-2010 12:51 AM


All times are GMT +5.5. The time now is 12:20 PM.