57.0k views
4 votes
Write a program that meets the following requirements.

Create two stages in a program
Create a pane using FlowPane in each stage
Add three buttons to each pane
Directions
Create a class named FlowPaneDemo extends Application
Create user interface using FlowPane
Add the instances of 3 Buttons to pane1 created by FlowPane and other 3 instances of Buttons using FlowPane to pane2
Create scene1 for pane1 with a specific size and scene2 for pane2 with a different size
Set different titles to two stages and display two stages
The output should look like the screen below
Provide appropriate Java comments

User Petrona
by
6.0k points

1 Answer

2 votes

Answer:

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.layout.FlowPane;

import javafx.stage.Stage;

import javafx.scene.control.Button;

public class FlowPaneDemo extends Application {

public void start(Stage primaryStage) {

// TODO Auto-generated method stub

//Creates a FlowPane for each stage.

FlowPane paneOne = new FlowPane();

FlowPane paneTwo = new FlowPane();

//Creates six Buttons, three for each Flow Pane.

Button buttonOne = new Button("Button One");

Button buttonTwo = new Button("Button Two");

Button buttonThree = new Button("Button Three");

Button buttonFour = new Button("Button Four");

Button buttonFive = new Button("Button Five");

Button buttonSix = new Button("Button Six");

//Adds the Buttons to the two FlowPanes.

paneOne.getChildren().add(buttonOne);

paneOne.getChildren().add(buttonTwo);

paneOne.getChildren().add(buttonThree);

paneTwo.getChildren().add(buttonFour);

paneTwo.getChildren().add(buttonFive);

paneTwo.getChildren().add(buttonSix);

//Creates two Scenes, using each of the FlowPanes.

Scene sceneOne = new Scene(paneOne, 250, 600);

Scene sceneTwo = new Scene(paneTwo, 320, 400);

//Makes a second Stage.

Stage secondaryStage = new Stage();

//Set the title and Scenes for the two Stages.

primaryStage.setTitle("First Stage");

primaryStage.setScene(sceneOne);

secondaryStage.setTitle("Second Stage");

secondaryStage.setScene(sceneTwo);

//Runs the show methods for the two Stages.

primaryStage.show();

secondaryStage.show();

}

public static void main(String[] args){

//Runs the launch method to start a stand-alone JavaFX application; only needed

//as I am running this in Eclipse.

Application.launch(args);

}

}

User David Hirst
by
5.4k points