Using Timers in Java
Threads can be confusing, and
multithreading isn't any better either. The use of timers is very simple JAVA milliseconds in a year Programme and allows several to work at the same time, with different
hours without interruption.
The first thing you need is an
import package:
import javax.swing.Timer;
Then state the timer:
Timer tmrTest = new timer (1,
myTimer);
1 is the interval in
milliseconds. This means this timer runs once every millisecond, fast.
myTimer is just the name of
ActionListener.
Starting a timer is also
required. Perhaps it is best to do this with a basic method.
tmrTest.start (); // There is
also a tmrTest.stop (). tmrTest.pause () and various other methods such as
finding the current beat time and setting the speed.
Next are the action listeners,
who are in the core class and are allowed to move around the class.
ActionListener myTimer = new
ActionListener () // Notice how the second timer parameter is named, not the
name of the timer!
{
public void actionPerformed
(ActionEvent evt)
{
// Do what you want every
millisecond
}}
};
And there it is. You can add as
many as you want. Just change the name AcitonListeners and don't forget to
start the timer!
In general, this is a much simpler
method than multiple threads. You can set the time manually instead of
continuously counting the variables in the thread. Also, the set times work the
same way on any system they are running on. Threads run as fast as current
processors allow. This means that on a computer with a better processor,
threads will run faster than without it. This can cause problems with your
application.
For More Details, Visit Us: how to insert multiple array values into database php
Comments
Post a Comment