Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Question
Book Icon
Chapter 14, Problem 14.1PE
Expert Solution & Answer
Check Mark
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.
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

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package, 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
Need help writing code to answer this question in Python! (image attached)
Need help with python code! How do I simplify my code for a beginner to understand, simple fixed format and centering? Such as:  print(f"As an int variable: {age_int:^7}") print(f"In numeric binary: {age_int:^7b}") My Code:name = input("Enter your name: ")print(f"In text name is: {' '.join(name)}")decimal_values = []binary_values = []for letter in name:   ascii_val = ord(letter)   binary_val = format(ascii_val, '08b')   decimal_values.append(str(ascii_val))   binary_values.append(binary_val)# Loop through each letter:print(f"In ASCII decimal: {' '.join(decimal_values)}")print(f"In ASCII binary: {' '.join(binary_values)}")# Ageage_str = input("Enter your age: ")age_int = int(age_str)print(f"As a string \"{age_str}\": {' '.join(age_str)}")age_decimal_values = []age_binary_values = []for digit in age_str:   ascii_val = ord(digit)   binary_val = format(ascii_val, '07b')   age_decimal_values.append(str(ascii_val))   age_binary_values.append(binary_val)print(f"In ASCII decimal: {'…
Don't use chatgpt or any other AI

Chapter 14 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package

Chapter 14.5, Problem 14.5.3CPChapter 14.5, Problem 14.5.4CPChapter 14.6, Problem 14.6.1CPChapter 14.6, Problem 14.6.2CPChapter 14.7, Problem 14.7.1CPChapter 14.7, Problem 14.7.2CPChapter 14.7, Problem 14.7.3CPChapter 14.8, Problem 14.8.1CPChapter 14.8, Problem 14.8.2CPChapter 14.9, Problem 14.9.1CPChapter 14.9, Problem 14.9.2CPChapter 14.9, Problem 14.9.3CPChapter 14.10, Problem 14.10.1CPChapter 14.10, Problem 14.10.2CPChapter 14.10, Problem 14.10.3CPChapter 14.10, Problem 14.10.4CPChapter 14.10, Problem 14.10.5CPChapter 14.11, Problem 14.11.1CPChapter 14.11, Problem 14.11.2CPChapter 14.11, Problem 14.11.3CPChapter 14.11, Problem 14.11.4CPChapter 14.11, Problem 14.11.5CPChapter 14.11, Problem 14.11.6CPChapter 14.11, Problem 14.11.7CPChapter 14.11, Problem 14.11.8CPChapter 14.11, Problem 14.11.9CPChapter 14.11, Problem 14.11.10CPChapter 14.11, Problem 14.11.11CPChapter 14.12, Problem 14.12.1CPChapter 14, Problem 14.1PEChapter 14, Problem 14.2PEChapter 14, Problem 14.3PEChapter 14, Problem 14.4PEChapter 14, Problem 14.5PEChapter 14, Problem 14.6PEChapter 14, Problem 14.7PEChapter 14, Problem 14.9PEChapter 14, Problem 14.10PEChapter 14, Problem 14.11PEChapter 14, Problem 14.12PEChapter 14, Problem 14.13PEChapter 14, Problem 14.14PEChapter 14, Problem 14.15PEChapter 14, Problem 14.16PEChapter 14, Problem 14.17PEChapter 14, Problem 14.18PEChapter 14, Problem 14.19PEChapter 14, Problem 14.20PEChapter 14, Problem 14.21PEChapter 14, Problem 14.22PEChapter 14, Problem 14.23PEChapter 14, Problem 14.24PEChapter 14, Problem 14.25PEChapter 14, Problem 14.27PEChapter 14, Problem 14.28PEChapter 14, Problem 14.29PE
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Fundamentals of Information Systems
Computer Science
ISBN:9781337097536
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning