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
What are the major threats of using the internet? How do you use it? How do children use it? How canwe secure it? Provide four references with your answer. Two of the refernces can be from an article and the other two from websites.
Assume that a string of name & surname is saved in S. The alphabetical characters in S can be in lowercase and/or uppercase letters. Name and surname are assumed to be separated by a space character and the string ends with a full stop "." character. Write an assembly language program that will copy the name to NAME in lowercase and the surname to SNAME in uppercase letters. Assume that name and/or surname cannot exceed 20 characters. The program should be general and work with every possible string with name & surname. However, you can consider the data segment definition given below in your program. .DATA S DB 'Mahmoud Obaid." NAME DB 20 DUP(?) SNAME DB 20 DUP(?) Hint: Uppercase characters are ordered between 'A' (41H) and 'Z' (5AH) and lowercase characters are ordered between 'a' (61H) and 'z' (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is 1 where for uppercase letters it is 0. For example, Letter 'h' Binary ASCII 01101000 68H 'H'…
What did you find most interesting or surprising about the scientist Lavoiser?

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
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