Hello everyone,
I am writing code to get my semi that I drew with graphics across the screen. This code works; however, it only runs the movement function once. I want it to continue repeating the timer task until the semi has moved completely off the screen. How can I adjust my code to accomplish that?
Thank you in advance for your help!
public class DrivingVehicle extends Application { int x = 10; Semi semi = new Semi(); @Override public void start(Stage primaryStage) { Group root = new Group(semi); Timer timer = new Timer(); timer.schedule(task,1500l); Scene scene = new Scene(root, 500, 400, Color.BLUE); primaryStage.setTitle("Driving semi"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } TimerTask task = new TimerTask() { public void run() { semi.setTranslateX(x); x+=10; } }; }