Why doesnt the ball move 10 then wait 1000ms then repeat 10 times
Hi I need help with my Java FX application. I want the ball to move 10 then wait then move again and repeat. I have created my button, circle and anchorpane in Scene Builder. The ball always only move at the end of the for loop please help. Here is my code public class Main extends Application{ public static void main(String [] args){ launch(args); } @Override public void start ( Stage stage ) throws Exception { Parent loginFOrm = FXMLLoader.load (getClass().getResource ("Resources/Bounce.fxml")); Scene loginform = new Scene(loginFOrm); stage.setScene (loginform); stage.show (); } } public class Bouncecontroller { @FXML Button start; @FXML Circle ball; boolean gameRunning; double ballX, ballY = 0; public void startGame ( MouseEvent mouseEvent ) throws InterruptedException { start.setVisible (false); gameRunning = true; for (int i = 0; i < 10; i++) { ballX = ball.getCenterX () + 10; System.out.println (ballX); sleep(1000); ball.setTranslateX (ballX); } } }