Solved

decreasing value of cell dynamycally

Posted on 2004-08-10
7
195 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
ID: 11764426
use timers for that
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11764442
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
ID: 11786177
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
ID: 11850738
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
ID: 11865663
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 37
MySqlDump not dumping triggers 1 43
iterator/ListIterator approach 17 39
What's wrong with this code? 4 25
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

792 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