Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Run Listing 14.9, p. 550 (in zipped NB project for Chapter 14). You'll need to download the image file us.gif and add it to your

image text in transcribedimage text in transcribed

Run Listing 14.9, p. 550 (in zipped NB project for Chapter 14). You'll need to download the image file us.gif and add it to your project OR use the URL that you find in the code. Take a screenshot of the window and paste it into your document. Which method did you use to display the flag? Listing 14.9 displays an image in three image views, as shown in Figure 14.14. Listing 14.9 ShowImage. Java 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 creatw an HBox Pane pane = new HBox(10): pane.setPadding(new Insets(5, 5, 5, 5)): create an image Image image = new Image("image/us. gif"): add an image view to pane pane getChildren().add(new ImageView(image)): create an image view ImageView imageView2 = new ImageView(image): set image view properties imageView2.setFitHeight(100): imageView2.setFitWidth(100): pane.getChi1dren().add(i mageView2): add an image to ImageView imageView3 = new ImageView(image): create an image imageView3.setRotate(90): rotate an image pane.getChi1dren().add(imageView3): add an image to//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 } } Modify Listing 14.14 to use three different styles. Change the text that is displayed to something of your own creation. Copy and paste a screenshot of the results into your document. The program creates an HBox (line 14). An HBox is a pane that places all nodes horizontally in one row. The program creates an Image, and then an ImageView for displaying the iamge, and places the ImageView in the HBox (line 17). The program creates the second ImageView (line 19), sets its fitHeight and fitWidth properties (lines 20-21) and places the ImageView into the HBox (line 22). The program creates the third ImageView (line 24), rotates it 90 degrees (line 25), and places it into the HBox (line 26). The setRotate method is defined in the Node class and can be used for any node. Note that an Image object can be shared by multiple nodes. In this case, it is shared by three ImageView. However, a node such as ImageView cannot be shared. You cannot place an ImageView multiple times into a pane or scene. Note that you must place the image file in the same directory as the class file, as shown in the following figure. If you use the URL to locate the image file, the URL protocal http://must be present. So the following code is wrong. new Image ("www.cs.armstrong.edu/liang/image/us.gif"): It must be replaced by new Image ("http;//www.cs.armstrong.edu/liang/image/us.gif")

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions