Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

a simple java timer

Thread view: 
Jimbob - 27 Nov 2003 12:54 GMT
Just wondering, has anyone here ever used java.swing.timer  if so, have you
got any examples? i cant seem to find many on google :s
Rhino - 27 Nov 2003 13:38 GMT
> Just wondering, has anyone here ever used java.swing.timer  if so, have you
> got any examples? i cant seem to find many on google :s

The technique for using a Swing timer is discussed in the Java Tutorial in
the Swing chapter. A complete example, ProgressBarDemo.java, is provided and
discussed in this topic. Links to discussions and examples of
general-purpose timers also appear on that same page.

Here is the URL:
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html

Rhino
Petarian - 27 Nov 2003 16:15 GMT
One comment. If you use this timer inside a server process, without any
GUI, make sure to use headless env.
(http://java.sun.com/j2se/1.4.2/docs/guide/awt/AWTChanges.html#headless)

I learned my lesson the hard way :-(

Pete

>  
>
[quoted text clipped - 19 lines]
>
>  

Signature

You don't pay to get spam, why pay to clean it?
Visit http://www.spammarshall.com to create an account for free
<http://www.spammarshall.com

Roedy Green - 27 Nov 2003 20:42 GMT
>One comment. If you use this timer inside a server process, without any
>GUI, make sure to use headless env.
You could also use java.util.Timer

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 27 Nov 2003 20:41 GMT
>Just wondering, has anyone here ever used java.swing.timer  if so, have you
>got any examples? i cant seem to find many on goo

  /**
   * Start periodic timer to unhighlight cells.
   */
  void startTimer()
     {
     final ActionListener refresher = new ActionListener()
        {
        public void actionPerformed( ActionEvent evt )
           {
          ...
              }
           }
        };
     periodic =  new Timer( Config.FADE_UPDATE_FREQUENCY, refresher
);
     periodic.start();
     }
Timer periodic;

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Christian Kaufhold - 28 Nov 2003 11:15 GMT
>      periodic =  new Timer( Config.FADE_UPDATE_FREQUENCY, refresher

frequency != period

Christian
Signature

And in short, I was afraid.

Chris Smith - 28 Nov 2003 16:24 GMT
> >      periodic =  new Timer( Config.FADE_UPDATE_FREQUENCY, refresher
>
> frequency != period

Christian,

Can you explain further?  A common definition of these terms would have
frequency be the multiplicative inverse of period, so that anything with
a frequency would also have a period, and so would qualify as
"periodic".  I can't find a more specific definition in the API docs for
javax.swing.Timer, so what are you referring to?

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Christian Kaufhold - 28 Nov 2003 17:18 GMT
>> >      periodic =  new Timer( Config.FADE_UPDATE_FREQUENCY, refresher
>>
[quoted text clipped - 7 lines]
> "periodic".  I can't find a more specific definition in the API docs for
> javax.swing.Timer, so what are you referring to?

The first argument to the Timer constructor is a period (time (actually
milliseconds) between events), not a frequency (number of events per time).

Therefore Config.FADE_UPDATE_FREQUENCY should be called
Config.FADE_UPDATE_PERIOD (or _DELAY, but IMO that does not imply repeti-
on while the Timer clearly seems to be used in periodic mode here).

Christian
Signature

And in short, I was afraid.

Roedy Green - 28 Nov 2003 19:08 GMT
>Therefore Config.FADE_UPDATE_FREQUENCY should be called
>Config.FADE_UPDATE_PERIOD

That is true.  However, lay people who might do the configuring are
more likely to understand the term "frequency" so I deliberately chose
the inaccurate name.   I explain in the notes for it that it is
measured in seconds, not events/second.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Chris Smith - 28 Nov 2003 19:11 GMT
> >> >      periodic =  new Timer( Config.FADE_UPDATE_FREQUENCY, refresher

> The first argument to the Timer constructor is a period (time (actually
> milliseconds) between events), not a frequency (number of events per time).
>
> Therefore Config.FADE_UPDATE_FREQUENCY should be called
> Config.FADE_UPDATE_PERIOD (or _DELAY, but IMO that does not imply repeti-
> on while the Timer clearly seems to be used in periodic mode here).

Right!  Gotcha.  I just wondered if I'd missed some technical detail
about the way timers worked... instead, it turns out I just wasn't
applying your comment correctly.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.