Question: How to change my code so that it looks like the photo (needs to have a finish line and print the winner). import javafx.application.*; import

How to change my code so that it looks like the photo (needs to have a finish line and print the winner).

import javafx.application.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.image.*; import javafx.scene.control.*; import javafx.scene.control.Alert.*; import javafx.scene.text.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.stage.*; import javafx.geometry.*; import javafx.animation.*; import java.io.*; import java.util.*;

public class Races extends Application { private Stage stage; private Scene scene; private VBox root; private static String[] args; private final static String ICON_IMAGE="embars.gif"; private final static int DEFAULT = 5; private final static int WIDTH = 15; private int iconWidth; private int iconHeight; private CarRacer racer = null; private Image carImage = null;

private AnimationTimer timer; private static int carNum; public static void main(String [] _args) { args = _args; if(args.length == 0){ carNum = DEFAULT; } else{ carNum = Integer.parseInt(args[0]); } launch(args); } public void start(Stage _stage) { stage = _stage; stage.setTitle("Off to the Races"); stage.setOnCloseRequest( new EventHandler() { public void handle(WindowEvent evt) { System.exit(0); } }); root = new VBox(); initializeScene(); } public void initializeScene() { try { carImage = new Image(new FileInputStream(ICON_IMAGE)); } catch(Exception e) { System.out.println("Exception: " + e); System.exit(1); } iconWidth = (int)carImage.getWidth(); iconHeight = (int)carImage.getHeight(); scene = new Scene(root, iconWidth*WIDTH, iconHeight*carNum); scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm()); stage.setScene(scene); stage.show(); System.out.println("Starting race..."); Vector cars = new Vector(); Vector threads = new Vector(); for(int i=1; i500){ break; } update(); } } public void update() { racePosX += (int)(Math.random() * iconWidth / 10); aPicView.setTranslateX(racePosX); if(racePosX>800) racePosX=0; } } }

How to change my code so that it looks like the photo

Off to the Races - Dave Patric 60 Winner is #2 00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!