Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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; } } }

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions