Question
The partial JavaFX program below simulates the display of a stop light. You can control the lights by clicking on a radio button representing each
The partial JavaFX program below simulates the display of a stop light. You can control the lights by clicking on a radio button representing each of the three colors. Your task is to write the code to put the radio buttons on the screen and program them to change the colors. Look at the bolded comments in the code below for the instructions and where you are to insert your code. There are two places for your code. Be sure to complete both of them. Just write your code in the space provided by Blackboard, don't include the original existing code. (15 pts)
***************************************************** //
public class StopLight extends Application { private double paneWidth = 200; private double paneHeight = 90;
@Override // Override the start method in the Application class public void start(Stage primaryStage) { Pane pane = new Pane(); Circle circleRed = new Circle(paneWidth / 2, 20, 10); Circle circleYellow = new Circle(paneWidth / 2, 50, 10); Circle circleGreen = new Circle(paneWidth / 2, 80, 10); circleRed.setStroke(Color.BLACK); circleYellow.setStroke(Color.BLACK); circleGreen.setStroke(Color.BLACK); circleRed.setFill(Color.WHITE); circleYellow.setFill(Color.WHITE); circleGreen.setFill(Color.WHITE);
Rectangle rectangle = new Rectangle(paneWidth / 2 - 15, 5, 30, 90); rectangle.setFill(Color.WHITE); rectangle.setStroke(Color.BLACK); pane.getChildren().addAll(rectangle, circleRed, circleYellow, circleGreen);
BorderPane borderPane = new BorderPane(); borderPane.setCenter(pane);
// *** Insert your code here to create the three radio buttons (representing Red, Green, and Yellow), put // *** them in ToggleGroup, add them to a Horizonzontal Pane, centered, and place that in the bottom region // *** of borderpane.
// Create a scene and place it in the stage Scene scene = new Scene(borderPane, paneWidth, paneHeight + 40); primaryStage.setTitle("StopLight"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage // Insert your code here to program the actions that take place when the radio buttons are clicked. There are // three action events, one for each radio button. Remember only one of the lights on the stoplight should be // colored at a time.
}
// Sto Red Yellow Green
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started