Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
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

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package, 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
1. Level the resources (R) for the following network. Show exactly which activity is being moved at each cycle and how many days it is being moved. Show all cycles required to utilize the free float and the back float. B H 3 3 L 2 0-0-0 A C F G K N P Q T 0 3 2 2 1 2-2-2 7R 8R 4R 6R 4R 2R 5R 4R D 1 2R 2 M 000 4R 2 4R 1 2 3 4 B5 B BE B 5 5 7 D 2003 C NO C MBSCM В H 5 2 F 7 7 8 SH2F80 5 Н Н 6 7 7L3G4+ 6H2G4 J 4 4 14 8 L K 00 36 9 10 11 12 13 14 15 P 2 Z+ N N 4 4 Z t 2334 4 Σ + M M 4 +
2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1H
Need Java method please. Thank you.

Chapter 16 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package

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