guys, I'm just trying to create 3 Radio Buttons that will change my background color in JavaFX. And I got stuck, I got this error "Symbols not found" in the updateBackGround() method, specifically the "pane1.setBackground(new...."
Java could not find the "pane1" symbol. Please help me. Thank you so much. Below is my code.
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
public class Project2 extends Application
{
public RadioButton RedButton;
public RadioButton BlueButton;
public RadioButton GreenButton;
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage)
{
Pane myPane1 = pane1();
Scene scene1 = new Scene(myPane1);
primaryStage.setScene(scene1);
primaryStage.setTitle("HAI VO");
primaryStage.show();
}
public Pane pane1()
{
ToggleGroup group1 = new ToggleGroup();
RedButton = new RadioButton("RED");
RedButton.setToggleGroup(group1);
RedButton.setOnAction(event -> updateBackGround());
BlueButton = new RadioButton("BLUE");
BlueButton.setToggleGroup(group1);
BlueButton.setOnAction(event -> updateBackGround());
BlueButton.setSelected(true);
GreenButton = new RadioButton("Green");
GreenButton.setToggleGroup(group1);
GreenButton.setOnAction(event -> updateBackGround());
GridPane pane1 = new GridPane();
pane1.add(RedButton,5,0);
pane1.add(GreenButton,10,0);
pane1.add(BlueButton,20,0);
pane1.setHgap(5);
pane1.setVgap(5);
pane1.setPadding(new Insets(20,20,20,20));
updateBackGround();
return pane1;
}
public void updateBackGround()
{
if (RedButton.isSelected()) {
pane1.setBackground(new Background(new BackgroundFil(Color.RED,CornerRadii.EMPTY, Insets.EMPTY)));
}
if (BlueButton.isSelected()) {
pane1.setBackground(new Background(new BackgroundFill(Color.BLUE,CornerRadii.EMPTY, Insets.EMPTY)));
}
if (GreenButton.isSelected()) {
pane1.setBackground(new Background(new BackgroundFill(Color.GREEN,CornerRadii.EMPTY, Insets.EMPTY)));
}
}
}
`