Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
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, 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
x3003 x3008 1110 0000 0000 1100 1110 0010 0001 0000 0101 0100 1010 0000 x3004 0010 0100 0001 0011 x3005 0110 0110 0000 0000 X3006 0110 1000 0100 0000 x3007 0001 0110 1100 0100 0111 0110 0000 What does the following LC-3 program do? Trace Step by Step, SHOW ALL YOUR WORK. x3001 x3002 0000 x3009 0001 0000 0010 0001 X300A 0001 0010 0110 0001 x300B 0001 0100 1011 1111 x300C 0000 0011 1111 1000 X300D 1111 0000 0010 0101 x300E 0000 0000 0000 0101 x300F 0000 0000 0000 0100 x3010 0000 0000 0000 0011 x3011 0000 0000 0000 0110 x3012 0000 0000 0000 0010 x3013 x3014 0000 0000 0000 0000 0000 0100 0000 0111 x3015 0000 0000 0000 0110 x3016 0000 0000 0000 1000 x3017 0000 0000 0000 0111 x3018 0000 0000 0000 0101
2) Assume a local area network has four host computers (h1, h2, h3 & h4) and they are connected to the internet through a NAT router (s1). The host computers use private IP address space: 192.168.2/24. Each host is trying to establish 2 TCP connections to a remote webserver through the NAT router. The IP address of the webserver is: 130.12.11.9. Now do the following: 1 a. Assign IP addresses to the interfaces of the hosts and the router. For the router, assign arbitrary addresses. List these addresses. b. Now create a NAT translation table as taught in the class for all TCP connections. Assign arbitrary port numbers as required.
1) Consider the following network. Host h6 10.3.0.6 Host h5 10.3.0.5 Host h1 10.1.0.1 OpenFlow controller m 2 3 4 Host h4 10.2.0.4 Host h2 10.1.0.2 Host h3 10.2.0.3 The desired forwarding behavior for the datagrams arriving at s2 is as follows: a) any datagrams arriving on input port 1 from hosts h5 or h6 that are destined to hosts h1 or h2 should be forwarded over output port 2; b) any datagrams arriving on input port 2 from hosts h1 or h2 that are destined to hosts h5 or h6 should be forwarded over output port 1; c) any arriving datagrams on input ports 1 or 2 and destined to hosts h3 or h4 should be delivered to the host specified; d) hosts h3 and h4 should be able to send datagrams to each other. Create a flow table for s2 that implement these forwarding behaviors. Your table should have 2 columns one for match and the other for actions, as taught in the class.

Chapter 16 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)

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