Переключение сцен в javafx с помощью таймера

#user-interface #scene

#пользовательский интерфейс #сцена

Вопрос:

Я хочу переключать сцены в своей программе javafx с помощью таймера. Я построил таймер, который работает, но замена никогда не происходит. Я хочу отобразить экран, похожий на тот, который я построил. Я новичок в программировании.

 // select button  sButton.row = 2;  sButton.column = 2;  Button activeButton = myButtons[sButton.row][sButton.column];  activeButton.setText(SelectedCellText);    TimerTask task = new TimerTask(){  int secondsPassed = 0;  @Override  public void run(){  secondsPassed  ;  System.out.println("Seconds passed: "   secondsPassed);  if(secondsPassed == 2000)  {  stage.setScene(scene3); //Scene never swaps here.  System.out.println("Scene Swap");  }  };  };   Timer timer = new Timer();  timer.schedule(task,0,2000 );  try{  Thread.sleep(2000);  }  catch(InterruptedException exc)  {    }  timer.cancel();       //GUI Display  BorderPane bp = new BorderPane();  //bp.setLeft(timerLabel);  bp.setTop(pointsLabel);  bp.setRight(roundLabel);  bp.setBottom(exitButton);  bp.setPadding(new Insets(20,20,20,20));  bp.setAlignment(exitButton, Pos.BOTTOM_CENTER);  bp.setAlignment(roundLabel, Pos.CENTER_RIGHT);  bp.setCenter(gameBoard);  scene2 = new Scene(bp);  return scene2; } '