//import javafx.scene.control.*; import javafx.scene.text.Font; import javafx.event.ActionEvent; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView; /** * Use this template to create Apps with Graphical User Interfaces. * * @author YOUR NAME */ public class ImageViewer extends Application { // TODO: Instance Variables for View Components and Model // TODO: Private Event Handlers and Helper Methods /** * This is where you create your components and the model and add event * handlers. * * @param stage The main stage * @throws Exception */ @Override public void start(Stage stage) throws Exception { Pane root = new Pane(); Scene scene = new Scene(root, 400, 500); // set the size here stage.setTitle("ImageView"); // set the window title here stage.setScene(scene); // TODO: Add your GUI-building code here Image image = new Image("thecar.jpg"); ImageView imageView = new ImageView(image); //Setting the position of the image imageView.setX(1); imageView.setY(1); //setting the fit height and width of the image view imageView.setFitHeight(500); imageView.setFitWidth(350); //setting the preserve ratio of the image view imageView.setPreserveRatio(true); // 1. Create the model // 2. Create the GUI components // 3. Add components to the root root.getChildren().addAll(imageView); // 4. Configure the components (colors, fonts, size, location) // 5. Add Event Handlers and do final setup // 6. Show the stage stage.show(); } /** * Make no changes here. * * @param args unused */ public static void main(String[] args) { launch(args); } }