Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

va program that i need help ..need to add radio buttons to change the traffic li

ID: 3691587 • Letter: V

Question

 va program that i need help ..need to add radio buttons to change the traffic lights on the program.  import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.stage.Stage;    public class lab8 extends Application{         double paneWidth = 200;         double paneHeight = 100;                  public void start(Stage pstage) {                 Pane pane = new Pane();                 Circle redlight = new Circle(paneWidth/2, 20, 10);                 Circle yellowlight = new Circle(paneWidth/2, 50, 10);                 Circle greenlight = new Circle(paneWidth/2, 80, 10);                 redlight.setFill(Color.RED);                 redlight.setStroke(Color.BLACK);                 yellowlight.setFill(Color.WHITE);                 yellowlight.setStroke(Color.BLACK);                 greenlight.setFill(Color.WHITE);                 greenlight.setStroke(Color.BLACK);                                  Rectangle rect = new Rectangle(paneWidth/2 -15,5, 30, 90 );                 rect.setStroke(Color.BLACK);                 rect.setFill(Color.GOLD);                                  pane.getChildren().addAll(rect, redlight, yellowlight, greenlight);                                  // associate the pane to a scene                 Scene scene = new Scene(pane, 200, 300);                 pstage.setTitle("Lab 8");                 pstage.setScene(scene);                 pstage.show();         }          public static void main(String[] args) {                 // TODO Auto-generated method stub                 launch(args);         }  } 

Explanation / Answer

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class lab8 extends Application{
double paneWidth = 200;
double paneHeight = 100;
  
public void start(Stage pstage) {
Pane pane = new Pane();
Circle redlight = new Circle(paneWidth/2, 20, 10);
Circle yellowlight = new Circle(paneWidth/2, 50, 10);
Circle greenlight = new Circle(paneWidth/2, 80, 10);
redlight.setFill(Color.RED);
redlight.setStroke(Color.BLACK);
yellowlight.setFill(Color.WHITE);
yellowlight.setStroke(Color.BLACK);
greenlight.setFill(Color.WHITE);
greenlight.setStroke(Color.BLACK);
  
Rectangle rect = new Rectangle(paneWidth/2 -15,5, 30, 90 );
rect.setStroke(Color.BLACK);
rect.setFill(Color.GOLD);


Grid pane pane1=new Gridpane();
pane1.set alignment(pos.center);
pane1.setpadding(new Insets(5,5,5,5));
pane1.sethgap(5);
pane1.setvgape(5);
pane.getchildren().add(pane1);

circle circle(new circle(panewidth/2, 20, 10));
circle.setstroke(color.BLACK)
circle.setfill(color.RED);
pane1.add(circle,1,1);

circle circle1(new circle(panewidth/2, 50, 10));
circle1.setstroke(color.BLACK)
circle1.setfill(color.WHITE);
pane1.add(circle1,1,1);


circle.circle1(new circle(panewidth/2, 80, 10));
circle2.setstroke(color.BLACK)
circle2.setfill(color.WHITE);
pane1.add(circle,1,1);

RADIOBUTTON rbRED=new RADIOBUTTON("RED");
RADIOBUTTON rbRED=new RADIOBUTTON("YELLOW");
RADIOBUTTON rbRED=new RADIOBUTTON("GREEN");

ToggleGroup group=new ToggleGroup();
rbred.setToggleGroup(Group);
rbredyellow.setToggleGroup(Group);
rbgreen.setToggleGroup(Group);

HBOX hBox=new HBox(5);
hBox.getchildren().addAll(rbred,rdyellow,rbgreen);
hBox.setAlignment(pos.center);

Borederpane borderpane=new Borderpane();
borderpane.setcenter(pane);
borderpane.setbottom(hbox);

Scene scene = new Scene(pane, 200, 300);
pstage.setTitle("Lab 8");
pstage.setScene(scene);
pstage.show();
}

rbred.setonaction(e->{
circle.setfill(color.RED);
circle.setfill(color.WHITE);
circle.setfill(color.WHITE);
});

rbyellow.setonaction(e->{
circle.setfill(color.WHITE);
circle.setfill(color.YELLOW);
circle.setfill(color.WHITE);
});

rbgreen.setonaction(e->{
circle.setfill(color.WHITE);
circle.setfill(color.WHITE);
circle.setfill(color.GREEN);
});

public static void main(String[] args) {
  
launch(args);
}

}
}