Question
Book Icon
Chapter 14, Problem 14.1PE
Program Plan Intro

Program Plan:

  • Import required packages.
  • Declare a main class named “ch14_1” which extends the “Application” class.
    • Declare a “start ()” method which overrides the “start ()” method in the “Application” class. Inside this method,
      • Create a GridPane in order to display images.
      • Place the pane in center position using “setAlignment ()” method.
      • Set the horizontal and vertical gap for the pane using “setHgap ()” and “setVgap ()” functions respectively.
      • Create four ImageView objects to display all the images from the file.
      • Add all the four images on their respective position on the pane.
      • Create a scene and place it on the stage.
      • Set the title as “Exercise14_01”.
      • Display the stage on the window using “primaryStage.show()” method.
    • Declare a main method using “public static main”.
      • Launch the method using “launch ()” method.

Expert Solution & Answer
Check Mark
Program Description Answer

The below program displays four images on the GridPane as per the given image.

Explanation of Solution

Program:

//Import required packages

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.layout.GridPane;

import javafx.stage.Stage;

import javafx.scene.image.ImageView;

//Main class extends Application

public class ch14_1 extends Application

{

//Overrides the start method in the application

@Override

//start method

public void start(Stage primaryStage)

{

//Create a GridPane to display images

GridPane GP = new GridPane();

//Place the pane in center position

GP.setAlignment(Pos.CENTER);

/*set the horizontal and vertical gap for the pane*/

GP.setHgap(5);

GP.setVgap(5);

/*Create 4 image views to display 4 images and pass the url from the file name*/

ImageView IV1 = new ImageView("snaps/germany.gif");

ImageView IV2 = new ImageView("snaps/china.gif");

ImageView IV3 = new ImageView("snaps/fr.gif");

ImageView IV4 = new ImageView("snaps/us.gif");

/*Add image to the pane in the first row, first column*/

GP.add(IV1, 0, 0);

/*Add image to the pane in the second row, first column*/

GP.add(IV2, 1, 0);

/*Add image to the pane in the first row, second column*/

GP.add(IV3, 0, 1);

/*Add image to the pane in the second row, second column*/

GP.add(IV4, 1, 1);

//Create a scene and place it on the stage

Scene scene = new Scene(GP);

//Setting title

primaryStage.setTitle("Exercise14_01");

//Place the scene on the stage

primaryStage.setScene(scene);

//Display the stage on the window

primaryStage.show();

}

//Main method

public static void main(String[] args)

{

//Launch the application

launch(args);

}

}

Sample Output

Screenshot of the output

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version, Chapter 14, Problem 14.1PE

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
java script
Exercise 9.2 A student has found a summer job in a painting company. He is to estimate the amount of paint that the company needs to paint rectangular fields of different sizes. On average,   a) 0.2 kg (kilogram) of paint is needed to paint a one square meter area (0.2 kg/m2). b) 22 mg (milligram) of paint is needed to paint a one square centimetres area (22 mg/cm2). c) 19.6 T (Ton) of paint is needed to paint a one square km area (19.6 T/km2).  Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton). Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton). // P92.cpp - This program illustrates the use of namespaces…
***Microsoft Visual Studios (C++)***   Write a program that given two coordinate pairs and a third single coordinate will linearly interpolate or extrapolate the third second coordinate. For example, let's say at 50 degrees Celsius the length of a metal rod is 5.4 cm and at 60 degrees Celsius the length is 5.5cm. I can interpolate the length at 53 degrees Celsius by doing 5.4cm + 3*(.1/10)=5.43cm. Your program does not need to continuously run, but should prompt the user for two coordinate pairs, the third first coordinate and return the extrapolated or interpolated third second coordinate.

Chapter 14 Solutions

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version

Ch. 14.5 - Can you create an object of IntegerProperty using...Ch. 14.5 - Prob. 14.5.4CPCh. 14.6 - Prob. 14.6.1CPCh. 14.6 - Prob. 14.6.2CPCh. 14.7 - How do you create a color? What is wrong about...Ch. 14.7 - Prob. 14.7.2CPCh. 14.7 - Prob. 14.7.3CPCh. 14.8 - Prob. 14.8.1CPCh. 14.8 - Prob. 14.8.2CPCh. 14.9 - Prob. 14.9.1CPCh. 14.9 - Prob. 14.9.2CPCh. 14.9 - Prob. 14.9.3CPCh. 14.10 - Prob. 14.10.1CPCh. 14.10 - Prob. 14.10.2CPCh. 14.10 - Prob. 14.10.3CPCh. 14.10 - Prob. 14.10.4CPCh. 14.10 - Prob. 14.10.5CPCh. 14.11 - How do you display a text, line, rectangle,...Ch. 14.11 - Prob. 14.11.2CPCh. 14.11 - Prob. 14.11.3CPCh. 14.11 - Write code fragments to fill red color in a...Ch. 14.11 - Prob. 14.11.5CPCh. 14.11 - Prob. 14.11.6CPCh. 14.11 - Write code fragments to display the outline of the...Ch. 14.11 - Write code fragments to display the lower half of...Ch. 14.11 - Write code fragments to display a polygon...Ch. 14.11 - Write code fragments to display a polygon...Ch. 14.11 - Prob. 14.11.11CPCh. 14.12 - Prob. 14.12.1CPCh. 14 - Prob. 14.1PECh. 14 - Prob. 14.2PECh. 14 - (Display three cards) Write a program that...Ch. 14 - (Color and font) Write a program that displays...Ch. 14 - (Characters around circle) Write a program that...Ch. 14 - Prob. 14.6PECh. 14 - (Display random 0 or 1) Write a program that...Ch. 14 - (Create four fans) Write a program that places...Ch. 14 - (Display a cylinder) Write a program that draws a...Ch. 14 - Prob. 14.11PECh. 14 - (Display a bar chart) Write a program that uses a...Ch. 14 - Prob. 14.13PECh. 14 - (Display a rectanguloid) Write a program that...Ch. 14 - Prob. 14.15PECh. 14 - Prob. 14.16PECh. 14 - (Game: hangman) Write a program that displays a...Ch. 14 - Prob. 14.18PECh. 14 - (Plot the sine and cosine functions) Write a...Ch. 14 - (Draw an arrow line) Write a static method that...Ch. 14 - Prob. 14.21PECh. 14 - (Connect two circles) Write a program that draws...Ch. 14 - (Geometry: two rectangles) Write a program that...Ch. 14 - (Geometry: Inside a polygon?) Write a program that...Ch. 14 - Prob. 14.25PECh. 14 - Prob. 14.27PECh. 14 - (Random time) Modify the ClockPane class with...Ch. 14 - (Game: bean machine) Write a program that displays...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr