Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to execute a method() one after another??

Vadim FilatovVadim Filatov Member Posts: 1

У меня есть метод TIMER_funk()

    @FXML Label MINUTES;
    @FXML Label SECONDS;

    @FXML private Button StartTimer;
    @FXML private Button STOPTIMER;

    Timer timer_sec = new Timer();
    int sec;

    public void TIMER_funk(int seco)  {
        this.sec = seco;
        timer_sec.schedule(new TimerTask() {
            @Override
            public void run() {
                Platform.runLater(new Runnable() {      
                    @Override
                    public void run() {
                        if (sec > 0) {
                            sec--;
                            int minutes = sec / 60;
                            int seconds = sec % 60;
                            SECONDS.setTextFill(seconds < 4 ? Color.RED : Color.BLACK);
                            MINUTES.setText((minutes < 10?"0":"") + minutes);
                            SECONDS.setText((seconds < 10?"0":"") + seconds);
                        }else if(sec==0){timer_sec.cancel();return;}  
                    }  
                });
           }   
        }, 1000, 1000);      
    }

And I need thiis method execute in order - one after another
TIMER_funk(22);
TIMER_funk(33);
TIMER_funk(22);
TIMER_funk(33);

I have tried this:

Thread threadA = new Thread(new Runnable(){
    public void run(){
        {
            TIMER_funk(22);   
    //другие thread's отличвются только названием и TIMER_funk(33); TIMER_funk(44);
        }
    }
}, "Thread A");
threadA.start();
if(threadA.isAlive()==false){   
    threadA.join();
    threadB.start();
}

if(threadB.isAlive()==false){
    threadB.join();
    threadC.start();
}

BUT it doesn't work properly - all methods start working at once and speed of counting doubles.

Tagged:

Answers

Sign In or Register to comment.