Red Yellow Green (a) PE 16-2 TrafficLight Part 2 1. Automate the stoplight from PE16-1 so that it changes color automatically after an appropriate amount of time. (i.e. cycles like a real stoplight) 2. Replace the color buttons with a "start" and "stop" button to control the light.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I need part 2 put into this code!!!

 

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.geometry.Pos;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class TrafficLightCopy extends Application {
    @Override // Override the start method in the Application calss
    public void start(Stage primaryStage) {
        // Create a vbox
        VBox paneForCircles = new VBox(5);
        paneForCircles.setAlignment(Pos.CENTER);

        // Create three circles
        Circle c1 = getCircle();
        Circle c2 = getCircle();
        Circle c3 = getCircle();
        c1.setFill(Color.RED);

        // Place circles in vbox
        paneForCircles.getChildren().addAll(c1, c2, c3);

        // Create a rectangle
        Rectangle rectangle = new Rectangle();
        rectangle.setFill(Color.WHITE);
        rectangle.setWidth(30);
        rectangle.setHeight(100);
        rectangle.setStroke(Color.BLACK);
        rectangle.setStrokeWidth(2);
        StackPane stopSign = new StackPane(rectangle, paneForCircles);

        // Create a hbox
        HBox paneForRadioButtons = new HBox(5);
        paneForRadioButtons.setAlignment(Pos.CENTER);

        // Create radio buttons
        RadioButton rbRed = new RadioButton("Red");
        RadioButton rbYellow = new RadioButton("Yellow");
        RadioButton rbGreen = new RadioButton("Green");

        // Create a toggle group
        ToggleGroup group = new ToggleGroup();
        rbRed.setToggleGroup(group);
        rbYellow.setToggleGroup(group);
        rbGreen.setToggleGroup(group);
        rbRed.setSelected(true);
        paneForRadioButtons.getChildren().addAll(rbRed, rbYellow, rbGreen);

        // Create a border pane
        BorderPane pane = new BorderPane();
        pane.setCenter(stopSign);
        pane.setBottom(paneForRadioButtons);

        // Create and register handlers
        rbRed.setOnAction(e -> {
                    if (rbRed.isSelected()) {
                        c1.setFill(Color.RED);
                        c2.setFill(Color.WHITE);
                        c3.setFill(Color.WHITE);
                    }
            });

        rbYellow.setOnAction(e -> {
                    if (rbYellow.isSelected()) {
                        c1.setFill(Color.WHITE);
                        c2.setFill(Color.YELLOW);
                        c3.setFill(Color.WHITE);
                    }
            });

        rbGreen.setOnAction(e -> {
                    if (rbGreen.isSelected()) {
                        c1.setFill(Color.WHITE);
                        c2.setFill(Color.WHITE);
                        c3.setFill(Color.GREEN);
                    }
            });

        // Create a scene and place it in the stage
        Scene scene = new Scene(pane, 200, 150);
        primaryStage.setTitle("Traffic Light"); // Set the stage title
        primaryStage.setScene(scene); // Place the scene in the stage
        primaryStage.show(); // Display the stage
    }

    /** Return a circle */
    private Circle getCircle() {
        Circle c = new Circle(10);
        c.setFill(Color.WHITE);
        c.setStroke(Color.BLACK);
        return c;
    }
}

 

Yellow Green
(a)
PE 16-2 TrafficLight Part 2
Red
1. Automate the stoplight from PE16-1 so that it changes color automatically after an appropriate amount of
time. (i.e. cycles like a real stoplight)
2. Replace the color buttons with a "start" and "stop" button to control the light.
Transcribed Image Text:Yellow Green (a) PE 16-2 TrafficLight Part 2 Red 1. Automate the stoplight from PE16-1 so that it changes color automatically after an appropriate amount of time. (i.e. cycles like a real stoplight) 2. Replace the color buttons with a "start" and "stop" button to control the light.
Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Rendering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education