Question: 14.1 (Display images) Write a program that displays four images in a grid pane as shown in Figure 14.43a. The image files (uk.gif, ca.gif, china.gif

14.1 (Display images) Write a program that displays four images in a grid pane as shown in Figure 14.43a. The image files (uk.gif, ca.gif, china.gif and us.gif) have been provided for you in a zip file named image.zip.a

image.zip/image/ca.gif

image.zip/image/china.gif

image.zip/image/uk.gif

image.zip/image/us.gif

Can you show me where and how to add an image folder (Create a pane to hold the images views) with gif images on this code, to hold image views.

Java code is below:

/*********************************************************************************

* (Display images) Write a program that displays four images in a grid pane, as *

* shown in Figure 14.43a. *

*********************************************************************************/

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Label;

import javafx.scene.layout.GridPane;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.stage.Stage;

public class Exercise_01 extends Application {

@Override // Override the start method in the Application class

public void start(Stage primaryStage) {

// Create a pane to hold the images views

GridPane pane = new GridPane();

// Place nodes in the pane

pane.add(new ImageView(new Image("image/uk.gif")), 0, 0);

pane.add(new ImageView(new Image("image/ca.gif")), 1, 0);

pane.add(new ImageView(new Image("image/china.gif")), 0, 1);

pane.add(new ImageView(new Image("image/us.gif")), 1, 1);

// Create a scene and place it in the stage

Scene scene = new Scene(pane);

primaryStage.setTitle("Exercise_14_01"); // Set the stage title

primaryStage.setScene(scene); // Place the scene in the stage

primaryStage.show(); // Display the stage.

}

}

Please make sure you is the correct and working code. Thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!