Question
Book Icon
Chapter 16, Problem 16.1PE
Expert Solution & Answer
Check Mark
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.
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

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version, 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
Answer all of the questions with steps by step explanation to every question.
W Go Tools Window Help mac283_quiz3_fall2025.pdf Page 2 of 2 @ Q Q Û • ¨ ® - Qy Search X 00 01 11 10 0 1 1 1 0 1 1 1 1 1 A ABC 88% Problem 3. Draw the combinational circuit that directly implements the Boolean expression: F(x, y, z) = xyz + (y²+z) Problem 4. Find the truth table that describes the following circuit. y- z - X Problem 5. a) Describe how a decoder works and indicate typical inputs and outputs. b) How many inputs does a decoder have if it has 64 outputs? NOV 6 M tv♫ zoom
CPS 2390 Extra Credit Assignment For each problem, choose the best answer and explain how you arrived at your answer. (15 points each.) 1.If control is redirected to location x4444 after the execution of the following instructions, what should have been the relationship between R1 and R2 before these instructions were executed? Address Instruction x4400 1001100010111111 x4401 0001100100100001 x4402 0001100001000100 x4403 0000100001000000 A. R1 R2 (R1 was greater than R2) B. R1 R2 (R2 was greater than R1) C. R1 R2 (R1 and R2 were equal) = D. Cannot be determined with the given information. 2. If the value stored in RO is 5 at the end of the execution of the following instructions, what can be inferred about R5? Address x3000 Instruction 0101000000100000 x3001 0101111111100000 x3002 0001110111100001 x3003 0101100101000110 x3004 0000010000000001 x3005 0001000000100001 x3006 0001110110000110 x3007 0001111111100001 x3008 0001001111111000 x3009 0000100111111000 x300A 0101111111100000 A. The…

Chapter 16 Solutions

MyLab Programming with Pearson eText -- Access Card -- for Introduction to Java Programming and Data Structures, Comprehensive Version

Chapter 16.4, Problem 16.4.4CPChapter 16.5, Problem 16.5.1CPChapter 16.5, Problem 16.5.2CPChapter 16.5, Problem 16.5.3CPChapter 16.5, Problem 16.5.4CPChapter 16.6, Problem 16.6.1CPChapter 16.6, Problem 16.6.2CPChapter 16.6, Problem 16.6.3CPChapter 16.6, Problem 16.6.4CPChapter 16.7, Problem 16.7.1CPChapter 16.7, Problem 16.7.2CPChapter 16.7, Problem 16.7.3CPChapter 16.7, Problem 16.7.4CPChapter 16.8, Problem 16.8.1CPChapter 16.8, Problem 16.8.2CPChapter 16.8, Problem 16.8.3CPChapter 16.8, Problem 16.8.4CPChapter 16.9, Problem 16.9.1CPChapter 16.9, Problem 16.9.2CPChapter 16.9, Problem 16.9.3CPChapter 16.9, Problem 16.9.4CPChapter 16.10, Problem 16.10.1CPChapter 16.10, Problem 16.10.2CPChapter 16.10, Problem 16.10.3CPChapter 16.11, Problem 16.11.1CPChapter 16.11, Problem 16.11.2CPChapter 16.11, Problem 16.11.3CPChapter 16.12, Problem 16.12.1CPChapter 16.12, Problem 16.12.2CPChapter 16.12, Problem 16.12.3CPChapter 16.13, Problem 16.13.1CPChapter 16.13, Problem 16.13.2CPChapter 16.13, Problem 16.13.3CPChapter 16.14, Problem 16.14.1CPChapter 16.14, Problem 16.14.2CPChapter 16, Problem 16.1PEChapter 16, Problem 16.2PEChapter 16, Problem 16.3PEChapter 16, Problem 16.4PEChapter 16, Problem 16.5PEChapter 16, Problem 16.6PEChapter 16, Problem 16.7PEChapter 16, Problem 16.8PEChapter 16, Problem 16.9PEChapter 16, Problem 16.10PEChapter 16, Problem 16.11PEChapter 16, Problem 16.12PEChapter 16, Problem 16.13PEChapter 16, Problem 16.14PEChapter 16, Problem 16.15PEChapter 16, Problem 16.16PEChapter 16, Problem 16.17PEChapter 16, Problem 16.18PEChapter 16, Problem 16.19PEChapter 16, Problem 16.20PEChapter 16, Problem 16.21PEChapter 16, Problem 16.22PEChapter 16, Problem 16.25PEChapter 16, Problem 16.28PEChapter 16, Problem 16.29PEChapter 16, Problem 16.30PEChapter 16, Problem 16.31PE
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT