vignesh
vignesh

Reputation:

How to periodically poll some value using Java (Swing)?

I am using swing based model.My form contains one Jbutton its called "polling(function name is getvalue())".I have a function name as "getvalue()".This function does retrieve values(this value will change after some span of time) and print it in console. I want code and idea about, that function will call automatically every 5 minutes ( or some span of time interval)and retrieve values and print it in console.I want code using timer concept .

my button function is like

private void ActionPerformed(java.awt.event.ActionEvent evt) {

}

where will write my Automatic polling code.

Upvotes: 1

Views: 1463

Answers (1)

Mike Samuel
Mike Samuel

Reputation: 120516

From http://download.oracle.com/javase/tutorial/uiswing/misc/timer.html

A Swing timer (an instance of javax.swing.Timer) fires one or more action events after a specified delay. Don't confuse Swing timers with the general-purpose timer facility that was added to the java.util package in release 1.3. This page describes only Swing timers.

In general, we recommend using Swing timers rather than general-purpose timers for GUI-related tasks because Swing timers all share the same, pre-existing timer thread and the GUI-related task automatically executes on the event-dispatch thread. However, you might use a general-purpose timer if you don't plan on touching the GUI from the timer, or need to perform lengthy processing.

Upvotes: 1

Related Questions