Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaFX FlowPane setup. Trying to set up a window that has two pictures. I am jus

ID: 3730242 • Letter: J

Question

JavaFX FlowPane setup. Trying to set up a window that has two pictures. I am just looking for tips on how to setup my stage and scene in the first section. Over all I want (two picture spots) within the scene and a (pushbutton), along with a (listener) at bottom. I cannot add to my imports at top, I must follow design. Any tips on how to set this up would be appreciated.

Thank-you

import javafx.application.Application;

import javafx.event.ActionEvent;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.text.Text;

import javafx.stage.Stage;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.FlowPane;

//**********************************************************************

//             3-18-17

//

//

//**********************************************************************

public class GUIDriver extends Application

{

       private Text sumText;

       private PigDice p;

       private ImageView die1View, die2View;

          

       //------------------------------------------------------------------

       // Demonstrates Images of rolled dice

       //------------------------------------------------------------------

       public void start(Stage primaryStage)

       {     

             Image img = new Image("Die1Image.jpg, Die2Image.jpg.");

             ImageView imgView = new ImageView(img);

            

             FlowPane pane = new FlowPane(imgView);

             pane.setStyle("-fx-background-color: cornsilk");

            

            

             Scene scene = new Scene(pane, 500, 400);

            

             primaryStage.setTitle("Image Display");

             primaryStage.setScene(scene);

             primaryStage.show();

                                                        

       }

      

       //--------------------------------------------------------------------

       //

       //--------------------------------------------------------------------

       public void processButtonPress(ActionEvent event)

       {

             pigDice p = new pigDice();

             p.roll();

             sumText.setText("sum is: " + p.toString());

                   

             Button roll = new Button("roll dice!");

             roll.setOnAction(this::processButtonPress);

            

      

       //-------------------------------------------------------------------

       // optional depending on IDE

    //-------------------------------------------------------------------

       public static void main(String[] args)

           {

               launch(args);

           }       

       }

}

Explanation / Answer

import javafx.application.Application;

inport javafx.scene.Group;

import javafx.scene,Scene;

import javafx.scene.image.Image;

import javafx.scene.image.ImageView;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

public class HelloMenu extends Application{

@Override

puclic void start(Stage stage){

// Creating two ImageViews and setting image to the Image View

Image image = new Image("image.png");

ImageView iv1 = new ImageView();

iv1.setImage(image);

ImageView iv2 = new ImageView();

iv2.setImage(image);

//Creating the button with Action Listener

Button btn = new Button("roll dice);

btn.setOnAction(new EventHandler(){

@Override

public void handle(ActionEvent evnet){

System.out.println("Presseddd....");

}

});

//Creating Group to add the views to the panel

Group root = new Group();

Scene scene = new Scene(root);

Hbox box = new Hbox();

box.getChildren().add(iv1);

box.getChildren().iv2();

// Adding childrens to the root

root.getChildren().add(box);

root.getChildren().add(btn);

scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

stage.setTitle("ImageView");

stage.setWidth(500);

stage.setHeight(200);

stage.setScene(scene);

stage.sizeToScene();

stage.show();

}

publicstatic void main (String args[])

{

Application.launch(args);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote