Solved

decreasing value of cell dynamycally

Posted on 2004-08-10
7
187 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 84
couple of eclipse 5 36
table example 4 29
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 31
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

786 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