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, Comprehensive Version, Student Value Edition (11th Edition)
- Find the error: daily_sales = [0.0, 0,0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(7): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': ')arrow_forwardFind the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] for i in range(6): daily_sales[i] = float(input('Enter the sales for ' \ + days_of_week[i] + ': '))arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it and normalize it? Give two references with your answer.arrow_forward
- What are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Consider that the database offline is not allowed since people are connected to it and personal data might be bridged and not secured. Provide three refernces with you answer.arrow_forwardShould software manufacturers should be tolerant of the practice of software piracy in third-world countries to allow these countries an opportunity to move more quickly into the information age? Why or why not?arrow_forwardI would like to know about the features of Advanced Threat Protection (ATP), AMD-V, and domain name space (DNS).arrow_forward
- I need help to resolve the following activityarrow_forwardModern life has been impacted immensely by computers. Computers have penetrated every aspect of oursociety, either for better or for worse. From supermarket scanners calculating our shopping transactionswhile keeping store inventory; robots that handle highly specialized tasks or even simple human tasks,computers do much more than just computing. But where did all this technology come from and whereis it heading? Does the future look promising or should we worry about computers taking over theworld? Or are they just a necessary evil? Provide three references with your answer.arrow_forwardWhat are the steps you will follow in order to check the database and fix any problems with it? Have in mind that you SHOULD normalize it as well. Describe in full, consider the following:• Taking the database offline is not allowed since people are connected to it.• Personal data might be bridged and not secured. Provide three refernces with you answerarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningFundamentals of Information SystemsComputer ScienceISBN:9781337097536Author:Ralph Stair, George ReynoldsPublisher:Cengage Learning