Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
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

Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (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
What are the major threats of using the internet? How do you use it? How do children use it? How canwe secure it? Provide four references with your answer. Two of the refernces can be from an article and the other two from websites.
Assume that a string of name & surname is saved in S. The alphabetical characters in S can be in lowercase and/or uppercase letters. Name and surname are assumed to be separated by a space character and the string ends with a full stop "." character. Write an assembly language program that will copy the name to NAME in lowercase and the surname to SNAME in uppercase letters. Assume that name and/or surname cannot exceed 20 characters. The program should be general and work with every possible string with name & surname. However, you can consider the data segment definition given below in your program. .DATA S DB 'Mahmoud Obaid." NAME DB 20 DUP(?) SNAME DB 20 DUP(?) Hint: Uppercase characters are ordered between 'A' (41H) and 'Z' (5AH) and lowercase characters are ordered between 'a' (61H) and 'z' (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is 1 where for uppercase letters it is 0. For example, Letter 'h' Binary ASCII 01101000 68H 'H'…
What did you find most interesting or surprising about the scientist Lavoiser?

Chapter 16 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (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
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