Question
Task3: Rotate a Node Add ShowImage.java to your project. Run the program. You will get errors. Why? Because your image is not found. Download the
Task3: Rotate a Node
Add ShowImage.java to your project. Run the program. You will get errors. Why?
Because your image is not found. Download the image us.gif and save it under the directory of folder bin, where your .class files are saved. Create a new folder called image, to save all the images will be used by the program. Now your program should run correctly.
Your program can display an image using URL. Copy the following URL of an image to replace the local image:
Another image online: http://www.cs.armstrong.edu/liang/image/us.gif
Run your program.
Change code to display the three images in vertically order, instead of the current horizontal order. (HBox VBox) Why does the third image look like in the wrong position? Try to comment out the rotate method for the third image. Now run the program. Things look good. Can you conclude the reason why the third image looks in the wrong position initially?
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.image.Image; import javafx.scene.image.ImageView;
public class ShowImage extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane to hold the image views Pane pane = new HBox(10); pane.setPadding(new Insets(5, 5, 5, 5)); Image image = new Image("image/us.gif"); pane.getChildren().add(new ImageView(image)); ImageView imageView2 = new ImageView(image); imageView2.setFitHeight(100); imageView2.setFitWidth(100); pane.getChildren().add(imageView2);
ImageView imageView3 = new ImageView(image); imageView3.setRotate(90); pane.getChildren().add(imageView3); // Create a scene and place it in the stage Scene scene = new Scene(pane); primaryStage.setTitle("ShowImage"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started