I'm building a rock, scissors, paper application as a college homework. I should use radio-buttons and since it's a game, it should allows one selected button at a time.
I tried to create ToggleGroups and set one of the buttons as selected by default, but it's not working! When I run the application, it still allows me to choose more than one button :( What am I missing?
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("../view/QuilometrosPorLitroView.fxml"));
primaryStage.setTitle("Pedra, Papel, Tesoura");
primaryStage.setScene(new Scene(root, 428, 336));
primaryStage.setResizable(false);
primaryStage.show();
Controller.selectButtonDefault();
}
public static void main(String[] args) {
launch(args);
}
}
public class Controller {
@FXML
public static
RadioButton tesoura = new RadioButton();
@FXML
public static
RadioButton pedra = new RadioButton();
@FXML
public static
RadioButton papel = new RadioButton();
public static void selectButtonDefault() {
ToggleGroup group = new ToggleGroup();
tesoura.setToggleGroup(group);
tesoura.setSelected(true);
pedra.setToggleGroup(group);
papel.setToggleGroup(group);
}