Question
Book Icon
Chapter 16, Problem 16.1PE
Program Plan Intro

Program Plan:

  • Include the required import statement.
  • Define the main class.
    • Declare the necessary variables
    • Using start initialize the required.
      • Create the border pane, radio button, text field, toggle group and button.
      • Set everything into the panel.
      • Add the actions event to the button.
      • Create a scene and place the pane in the stage.
      • Set the title.
      • Place the scene in the stage.
      • Display the stage.
    • Define the main method using public static main.
      • Initialize the call.

Expert Solution & Answer
Check Mark
Program Description Answer

The below program will display the statement in different colors and move the statement left and right using GUI as follows:

Explanation of Solution

Program:

//import statement

import javafx.application.Application;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.RadioButton;

import javafx.scene.control.ToggleGroup;

import javafx.scene.layout.BorderPane;

import javafx.scene.layout.HBox;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.text.Font;

import javafx.scene.text.Text;

import javafx.stage.Stage;

//definition of "Test" class

public class Test extends Application

{

//declare the required variables

private double pane_width = 500;

private double pane_height = 150;

@Override

/*start method gets overridden in the application class*/

public void start(Stage pri_stage)

{

//create a text

Text t = new Text(20, 40, "Programming is fun");

//set the font

t.setFont(new Font("Times", 20));

//create a text

Pane p = new Pane();

//create a label

p.getChildren().add(t);

//set the style

p.setStyle("-fx-border-color: gray");

//create a radio buttons

RadioButton r_red = new RadioButton("Red");

RadioButton r_yellow = new RadioButton("Yellow");

RadioButton r_black = new RadioButton("Black");

RadioButton r_orange = new RadioButton("Orange");

RadioButton r_green = new RadioButton("Green");

//create a toggle group

ToggleGroup group = new ToggleGroup();

//set the toggle groups

r_red.setToggleGroup(group);

r_yellow.setToggleGroup(group);

r_black.setToggleGroup(group);

r_black.setSelected(true);

r_orange.setToggleGroup(group);

r_green.setToggleGroup(group);

//create a box

HBox h_box = new HBox(5);

//create a label

h_box.getChildren().addAll(r_red, r_yellow, r_black, r_orange, r_green);

//set the alignment

h_box.setAlignment(Pos.CENTER);

//create a button

Button bt_left = new Button("<=");

Button bt_right = new Button("=>");

//create a box for button

HBox h_boxForButtons = new HBox(5);

//create a label

h_boxForButtons.getChildren().addAll(bt_left, bt_right);

//set the alignment

h_boxForButtons.setAlignment(Pos.CENTER);

//create a border pane

BorderPane border_pane = new BorderPane();

//set the border pane

border_pane.setTop(h_box);

border_pane.setCenter(p);

border_pane.setBottom(h_boxForButtons);

// create a scene and place it in the stage

Scene scene = new Scene(border_pane, pane_width, pane_height + 40);

//set the stage title

pri_stage.setTitle("Exercise16_01");

//place the scene in the stage

pri_stage.setScene(scene);

//display the stage

pri_stage.show();

// action event for the buttons gets created

r_red.setOnAction(e->t.setStroke(Color.RED));

r_yellow.setOnAction(e->t.setStroke(Color.YELLOW));

r_black.setOnAction(e->t.setStroke(Color.BLACK));

r_orange.setOnAction(e->t.setStroke(Color.ORANGE));

r_green.setOnAction(e->t.setStroke(Color.GREEN));

bt_left.setOnAction(e->t.setX(t.getX() - 1));

bt_right.setOnAction(e->t.setX(t.getX() + 1));

}

//definition of main method

public static void main(String[] args)

{

//initilaize calls

launch(args);

}

}

Sample Output

Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition, Chapter 16, Problem 16.1PE

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
(2) You will need to use the module graphics.py for this program. Write a program that con- structs a window, invites the user to present two clicks for the opposite vertices of a rectangle and then draws a red rectangle with those two opposite vertices. Finally, prompt the user to click to close the window.
Modify the Dice Poker program from this chapter to include any or all ofthe following features:a) Splash Screen. When the program first fires up, have it print a shortintroductory message about the program and buttons for "Let's Play''and "Exit." The main interface shouldn't appear unless the user selects "Let's Play."b) Add a "Help" button that pops up another window displaying therules of the game (the payoffs table is the most important part).c) Add a high score feature. The program should keep track of the 10best scores. When a user quits with a good enough score, he/she isinvited to type in a name for the list. The list should be printed inthe splash screen when the program first runs. The high-scores listwill have to be stored in a file so that it persists between programinvocations.
(code on expo)Code an add screen that will allow the user to input information about a book, such as the title,author,genre and number of pages. You can can use the TextInput component to create text fields for each piece of information and a button to submit the information and add it to the library.

Chapter 16 Solutions

Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition

Ch. 16.4 - Prob. 16.4.4CPCh. 16.5 - Prob. 16.5.1CPCh. 16.5 - Can you apply all the methods for Labeled to...Ch. 16.5 - Prob. 16.5.3CPCh. 16.5 - Prob. 16.5.4CPCh. 16.6 - Prob. 16.6.1CPCh. 16.6 - Can you apply all the methods for TextInputControl...Ch. 16.6 - Prob. 16.6.3CPCh. 16.6 - Prob. 16.6.4CPCh. 16.7 - Prob. 16.7.1CPCh. 16.7 - Prob. 16.7.2CPCh. 16.7 - Prob. 16.7.3CPCh. 16.7 - Prob. 16.7.4CPCh. 16.8 - Prob. 16.8.1CPCh. 16.8 - Prob. 16.8.2CPCh. 16.8 - Prob. 16.8.3CPCh. 16.8 - Prob. 16.8.4CPCh. 16.9 - Prob. 16.9.1CPCh. 16.9 - Prob. 16.9.2CPCh. 16.9 - Prob. 16.9.3CPCh. 16.9 - How do you obtain the selected items and selected...Ch. 16.10 - Prob. 16.10.1CPCh. 16.10 - Prob. 16.10.2CPCh. 16.10 - Prob. 16.10.3CPCh. 16.11 - Prob. 16.11.1CPCh. 16.11 - Prob. 16.11.2CPCh. 16.11 - Prob. 16.11.3CPCh. 16.12 - Prob. 16.12.1CPCh. 16.12 - Prob. 16.12.2CPCh. 16.12 - How does the program check whether a player wins?...Ch. 16.13 - Prob. 16.13.1CPCh. 16.13 - Prob. 16.13.2CPCh. 16.13 - Prob. 16.13.3CPCh. 16.14 - Prob. 16.14.1CPCh. 16.14 - Prob. 16.14.2CPCh. 16 - Prob. 16.1PECh. 16 - Prob. 16.2PECh. 16 - (Traffic lights) Write a program that simulates a...Ch. 16 - (Create a miles/kilometers converter) Write a...Ch. 16 - (Convert numbers) Write a program that converts...Ch. 16 - (Demonstrate TextField properties) Write a program...Ch. 16 - Prob. 16.7PECh. 16 - (Geometry: two circles intersect?) Write a program...Ch. 16 - (Geometry: two rectangles intersect?) Write a...Ch. 16 - (Text viewer) Write a program that displays a text...Ch. 16 - (Create a histogram for occurrences of letters)...Ch. 16 - Prob. 16.12PECh. 16 - (Compare loans with various interest rates)...Ch. 16 - (Select a font) Write a program that can...Ch. 16 - (Demonstrate Label properties) Write a program to...Ch. 16 - Prob. 16.16PECh. 16 - Prob. 16.17PECh. 16 - (Simulation a running fan) Rewrite Programming...Ch. 16 - Prob. 16.19PECh. 16 - Prob. 16.20PECh. 16 - (Count-down stopwatch) Write a program that allows...Ch. 16 - (Play, loop, and stop a sound clip) Write a...Ch. 16 - (Racing cars) Write a program that simulates four...Ch. 16 - (Slide show) Programming Exercise 15.30 developed...Ch. 16 - Prob. 16.29PECh. 16 - (Pattern recognition: consecutive four equal...Ch. 16 - (Game: connect four) Programming Exercise 8.20...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education