Introduction to Java Programming and Data Structures  Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134700144
Author: Liang
Publisher: PEARSON
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

Introduction to Java Programming and Data Structures  Comprehensive Version (11th Edition), 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
7. a) Write down the 5 by 5 adjacency matrix for the undirected graph below (Figure 1). A C E B D Figure 1: Undirected Graph for Question 7. (a) b) Write a program that asks a user to enter the number of vertices in an undirected graph and then the adjacency matrix representing the undirected graph. The program, then, must display the number of edges in the given graph. You will find a sample run of the program below. Enter number of vertices: 3 Enter adjacency matrix: 0 1 1 1 0 0 1 0 0 Total number of edges: 2
13) What's a Map? Homework • Unanswered Select all true statements from the below. Multiple answers: Multiple answers are accepted for this question Select one or more answers and submit. For keyboard navigation. SHOW MORE v a The idea of a map is to be able to look up one value with another. Often the lookup value is called the key and the looked-up value is called simply the value. As such, we see that any data structure essentially performs the actions required of a map.
7. a) Write down the 5 by 5 adjacency matrix for the undirected graph below (Figure 1). A B C D Figure 1: Undirected Graph for Question 7. (a) b) Write a program that asks user to enter number of vertices in an undirected graph and then the adjacency matrix representing the undirected graph. The program, then, must display whether the given graph is connected or not. You will find two sample runs of the program below. Sample 1 Sample 2 Enter number of vertices: 3 Enter number of vertices: 3 Enter adjacency matrix: 0 1 1 10 0 1 0 0 Enter adjacency matrix: 0 1 0 1 0 0 0 0 0 The graph is connected. The graph is not connected.

Chapter 14 Solutions

Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)

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