Solved

decreasing value of cell dynamycally

Posted on 2004-08-10
7
172 Views
Last Modified: 2011-04-14
i have a table with fields,and i want that one of
these fields show a value(integer) that must be decreased dynamically each second.
how can i do this?
thanks,
0
Comment
Question by:kimo100
7 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
use timers for that
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
Comment Utility
int delay = 5000;   // delay for 5 sec.
    int period = 1000;  // repeat every sec.
    Timer timer = new Timer();
   
    timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
//              your table cells code here
            }
        }, delay, period);
0
 

Author Comment

by:kimo100
Comment Utility
i use JDK1.2,and the classes Timer and TimerTask don't exist.
could you tell me if there is some thing equivalent in this release of JDK.
thanks
0
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
Comment Utility
new Thread()
{
    public void run()
    {
        while (true)  // run forever
        {
            // your table cells code here.
            // sleep for one second
            Thread.sleep(1000);
        }
    }
}
0
 
LVL 13

Expert Comment

by:Webstorm
Comment Utility
Hi kimo100,

girionis's suggestion is the solution unless you want more time precision (launch the task even if the last was not terminated) :

class MyTimerTask extends Thread
{
    public void doJob()
    {
          try{
          for(;;)
          {
               synchronized(this)
               {
                    wait();

                    // ...

               }
          }
          }catch(Exception ex){}
    }

    public void run()
    {
          Thread jobth=null;
          try{
          jobth=new Thread(){
             public void run(){doJob();}
           };
          jobth.start();
          for(;;)
          {
               synchronized(this)
               {
                    notify();
                    Thread.sleep(1000);
               }
          }
          }catch(Exception ex){}
          jobth.interrupt();
    }
}

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
triangle challenge 4 75
noX challenge 17 75
pairstar challenge 2 41
word0 challenge 3 55
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now