Question

In: Computer Science

Write a JavaFX multiple stage application which has at least two stages, a primary one and a secondary one.

JavaFX Two-Stage Application

Write a JavaFX multiple stage application which has at least two stages, a primary one and a secondary one.

The primary stage should have a gridpane which has at least a 2*3 grid.

On each cell of the grid, please place a different node from at least one of the three types: a UI control or a shape or an image view, etc.

On the secondary stage, you should design a layout with binding property.

Your overall project design should reflect a theme, for example, a music event commercial, etc.

Solutions

Expert Solution

package com.chegg.music;


import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;


public class Main extends Application {


   @Override
   public void start(Stage primaryStage) {
       try {
           GridPane gridpane = new GridPane();


       Stage secondaryStage = new Stage();

           Button homeBt = new Button("Home");
           homeBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\home.jpg",secondaryStage);
                   }
               });
           Button treeBt = new Button("Tree");
           treeBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\tree.jpg",secondaryStage);
                   }
               });
           Button rabbitBt = new Button("Rabbit");
           rabbitBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\rabbit.jpg",secondaryStage);
                   }
               });
           Button tortoiseBt = new Button("Tortoise");
           tortoiseBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\tortoise.jpg",secondaryStage);
                   }
               });
           Button mickyMouseBt = new Button("Mouse");
           mickyMouseBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\mickyMouse.jpg",secondaryStage);
                   }
               });
           Button duckBt = new Button("Duck");
           duckBt.setOnAction(new EventHandler(){
                   @Override
                   public void handle(ActionEvent event) {
                       // TODO Auto-generated method stub
                       show("D:\\Chegg\\javafxChegg\\MusicLibrary\\src\\com\\chegg\\music\\duck.jpg",secondaryStage);
                   }
               });
           gridpane.add(homeBt, 0, 0);
           gridpane.add(treeBt, 1, 0);
           gridpane.add(rabbitBt, 2, 0);

           gridpane.add(tortoiseBt, 0, 1);
           gridpane.add(mickyMouseBt, 1, 1);
           gridpane.add(duckBt, 2, 1);

       Scene scene = new Scene(gridpane, 400, 100);
       primaryStage.setTitle("Library Welcome");
       primaryStage.setScene(scene);
       primaryStage.show();


       //

       } catch(Exception e) {
           e.printStackTrace();
       }
   }
/*
* show image as per name in new stage
*/
   public void show(String name, Stage secondaryStage){
       FileInputStream input = null;
       try {
           input = new FileInputStream(name);
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       Image image = new Image(input);
       ImageView imageView = new ImageView(image);
HBox hbox = new HBox(imageView);

Scene sceneImages = new Scene(hbox, 300, 300);
secondaryStage.setScene(sceneImages);
       secondaryStage.setTitle("Home");
       secondaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}


Related Solutions

Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
Write a JavaFX application that displays a Label containing the opening sentence or two from your...
Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b // FXBookQuote1a.java import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.stage.Stage; public class FXBookQuote1a...
This lab is designed to design an event driven animation application which JavaFX application implementing a...
This lab is designed to design an event driven animation application which JavaFX application implementing a racing car image. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process. Let the user pause/resume the animation with a button press/release and increase/decrease the car speed by pressing the up and down arrow keys. The car used for this application has the following attributes. Task(s) Task 1: Create a...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.
Please find at least one application of a multiple linear regression model in business analysis and...
Please find at least one application of a multiple linear regression model in business analysis and post your comments/thoughts and the web link of the information source,
Out of primary,secondary, and tertiary prevention, which one is the most important and why?
Out of primary,secondary, and tertiary prevention, which one is the most important and why?
Draw a schematic of a wastewater treatment plant, explain the primary and secondary treatment stages. Identify...
Draw a schematic of a wastewater treatment plant, explain the primary and secondary treatment stages. Identify the major pollutants removed in each stage. ( Please no too long answers )
A service process has three serial stages. The defect percentage at stage one is 7%. The...
A service process has three serial stages. The defect percentage at stage one is 7%. The defect percentage at stage two is 13%. And, the defect percentage at stage three is 15%. Use 5 decimals for probabilities and 2 decimals for sigma levels in the following situations. (a)[2] Situation A: the connection logic of the three stages is that a good overall outcome only happens if all three stages individually have good outcomes. Draw the event tree for this situation....
A service process has three serial stages. The defect percentage at stage one is 16%. The...
A service process has three serial stages. The defect percentage at stage one is 16%. The defect percentage at stage two is 13%. And, the defect percentage at stage three is 10%. Use 3 decimals for probabilities in the following situations. (a)[2] Situation A: the connection logic of the three stages is that a good overall outcome only happens if all three stages individually have good outcomes. Draw the event tree for this situation. Calculate the probability of defective overall...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT