Question

I am working in GWT technology.so i want to display in a text with values like 59,58,57...

For that i have written below code

 Timer timer =new Timer(){

        @Override
        public void run()
        {
            if(60>seconds)
            {
        getBox().setText(""+0+":"+""+(60-seconds));---this is the textbox   
        seconds++;
            }
            /*else{
                Window.alert("");
            }*/
        }
    };

    timer.scheduleRepeating(1000);

    if(seconds==60)
    {
        seconds=0;
    /*  timer.cancel();
    timer.run();*/
        f1();
    }

but if it reaches zero i need to start the Timer.But i am unable to do that.so can any one has an idea about how to display values in testbox for every 1000ms in a text box with loops?

Was it helpful?

Solution

If I'm reading your question right, it looks like you want to count down from a minute, but then restart the count at 60 when it reaches 0.

I'd start my seconds at 60 and count down from there. In your run method you can update the seconds variable.

Does something like this work?

int seconds = 60;
Timer timer = new Timer(){

    @Override
    public void run()
    {
        if(seconds>0)
        {
        seconds--;
        getBox().setText("0:"+(seconds > 9 ? seconds : "0" + seconds));
        }
        else{
            f1();
            seconds = 60;
        }
    }
};

timer.scheduleRepeating(1000);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top