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.
- Declare a “start ()” method which overrides the “start ()” method in the “Application” class. Inside this method,
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);
}
}
Screenshot of the output
Want to see more full solutions like this?
Chapter 14 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
- 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…arrow_forwardJava ( OOP ) Given programming code and corresponding outputs. You are required to either complete the missing part of the code or correct errors and rewrite the code as mentioned in each statement.arrow_forwardRevise Exercise 6.28 (Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows:Roll two dice. Each die has six faces representing values 1, 2, ..., and 6, respectively. Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps), you lose; if the sum is 7 or 11 (called natural), you win; if the sum is another value (i.e., 4, 5, 6, 8, 9, or 10), a point is established. Continue to roll the dice until either a 7 or the same point value is rolled. If 7 is rolled, you lose. Otherwise, you win.Your program acts as a single player.)to run it 10,000 times and display the number of winning games.arrow_forward
- 4.16 LAB: Interstate highway numbers Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90. Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west. Ex: If the input is: 90 the output is: I-90 is primary, going east/west. Ex: If the input is: 290 the output is: I-290 is auxiliary, serving I-90, going east/west. Ex: If the input is: 0 the output is: 0 is not a valid interstate highway number. Ex: If the input is: 200 the output is: 200 is not a valid interstate highway number. See Wikipedia for more info on highway numbering. 344614.2153518.qx3zqy7 Use Python. Don't use Java cause that's…arrow_forwardThank youarrow_forward5.7 LAB: Palindrome A palindrome is a word or a phrase that is the same when read both forward and backward Examples are: bob, sees, or never odd or even (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome Ex: If the input is: bob the output is: bob is a palindrome Ex: If the input is: bobby the output is: bobby is not a palindrome Hint: Start by removing spaces. Then check if a string is equivalent to it's reverse. 450052196680037 LAB ACTIVITY 5.7.1: LAB: Palindrome 1 word=input("Enter a word or phrase: ").strip().lower 2 3 without_space= word.replace("","") 4 5 if without_space=without_space[::-1]: print (word, "is a palindrome") print (word, "is not a palindrome") 6 7 8 9 main.py else: I 0/10 Load default template...arrow_forward
- 1. (5.8 in 8e) Show the value of x after each of the following statements is performed: a) x fabs(7.5); b) x floor(7.5); c) x fabs(0.0); d) x ceil(0.0); e) x fabs(-6.4); x ceil(-6.4); g) x ceil(-fabs(-8 floor(-5.5))); 2. (5.12 in 8e) Answer each of the following questions: a) What does it mean to choose numbers "at random"? b) Why is the rand function useful for simulating games of chance? c) Why would you randomize a program by using srand? Under what circumstances is it desirable not to randomize? d) Why is it often necessary to scale and/or shift the values produced by rand? 3. Define an array of 100 ints, and write a loop (including the body) to initialize every element in the array to 0. You can name the array whatever you'd like 4. In C, strings have a terminating character at the end of the array, while, for example, integer arrays do not. Why do you think this is?arrow_forward1. After generating rectangles of arbitrary size on a two-dimensional plane, write a program to find the following and show the result. (1) Structure rectangle member composition: center position (x,y), width, height (2) Existence range of rectangle: 0 to 100 in x and y directions (3) Rectangle size: 20≤w,h≤50 (4) Write a program that randomly generates 10 squares and finds Intersection over Union (IoU) between different squares. (Let the two squares be A and B, IoU(A, B) = ?∩?/?∪?) (5) Write the following functions: (a) A function that fills the contents of the structure (b) A function that calculates the IoU of two given rectangles (c) A function that displays the contents of the final structure (d) Other functions necessary for writing programs (6) IoU results between squares are output in the form of 10 X 10 C++ Program source (submit only .c or .cpp)arrow_forwardlab assignment 1.13 LAB: Introduction to Cyptography (classes/constructors) Cryptography is the practice of encryption. Information Security uses cryptography techniques to encrypt and decrypt data. A simple encryption method might take plaintext and mix up the letters using some predetermined pattern and then use that pattern to decrypt the data for reading. Ciphers are the algorithms used to put the data into its secret pattern and then systematically decrypt it for reading. This script is going to use a famous simple cipher called the Caesar Cipher. It is a substitution cipher where each letter in the text is 'shifted' in a certain number of places. It uses the alphabet as the primary pattern and then based on the shift number, it would shift all the letters and replace the alphabet with our pattern. For example, if our shift number was 3, then A would be replaced with D, if we performed a right shift. As an example: Text = "THE CAT IS VISIBLE AT MIDNIGHT" Ciphertext = "WKH FDW LV…arrow_forward
- Q.18 Discuss about following computer factors. 1) Speed 11) Interface III) Widgetsarrow_forwardA1.2 Bean MachineThe bean machine is a device for statistical experiments. It consists of an upright board with evenly spaced nails (or pegs) in a triangular form,.Balls are dropped from the opening at the top of the board. Every time a ball hits a nail, it has a 50% chance of falling to the left or to the right. The piles of balls are accumulated in the slots at the bottom of the board.Write a program to simulate the bean machine that has 8 slots as shown in the figure. Your program should prompt the user to enter the number of balls to drop. Simulate the falling of each ball by printing its path. For example, the path for the ball in LLRRLLR and the path for the ball in RLRRLRR. Note that there are 7 levels of nails, so your path should be 7 letters (not 8).Create an array called slots. Each element in slots store the number of balls in a slot. Each ball falls into a slot via a path. The number of “R”s in a path is the position of the slot where the ball falls. For example, for the…arrow_forward1.37 Basic output with variables (Java) This zyLab activity is intended for students to prepare for a larger programming assignment Warm up exercises are typically simpler and worth fewer points than a full programming assignment. Warm up exercises are ideally suited for an in-person scheduled lab meeting or as self-practice. The last section provides a full programming assignment A variable like userNum can store a value like an integer Extend the given program to print UserNum values as indicated (Submit for 2 points) (1) Output the users input Enter integer: 4 You entered: 4 (2) Extend to output the input squared and cubed Hint Compute squared as userNum UserNum (Submit for 2 points, so 4 points total) Enter integer: 4 You entered: 4 4 squared is 16 And 4 cubed is 64!! (3) Extend to get a second user input into userNum2. Output sum and product (Submit for 1 point, so 5 points total) Enter integer: 4 You entered: 4. 4 squared is 16 And 4 cubed is 64!! Enter another integer: 5 4+ 5 18…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education