import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.stage.Stage; import static javafx.application.Application.launch; /** * Use this template to create drawings in FX. Change the name of the class and * put your own name as author below. Change the size of the canvas and the * window title where marked and add your drawing code where marked. * * @author Dave Slemon */ public class TheCar extends Application { /** * Start method (use this instead of main). * * @param stage The FX stage to draw on * @throws Exception */ @Override public void start(Stage stage) throws Exception { Group root = new Group(); Scene scene = new Scene(root); Canvas canvas = new Canvas(600, 800); // Set canvas Size in Pixels stage.setTitle("The Car"); // Set window title root.getChildren().add(canvas); stage.setScene(scene); GraphicsContext gc = canvas.getGraphicsContext2D(); // YOUR CODE STARTS HERE Image image = new Image("thecar.jpg"); //Setting the image view ImageView imageView = new ImageView(image); //Setting the position of the image //imageView.setX(200); //imageView.setY(50); //setting the fit height and width of the image view //imageView.setFitHeight(200); //imageView.setFitWidth(100); //Setting the preserve ratio of the image view //imageView.setPreserveRatio(true); root.getChildren().addAll(imageView); // YOUR CODE STOPS HERE stage.show(); } /** * The actual main method that launches the app. * * @param args unused */ public static void main(String[] args) { launch(args); } }