import javafx.application.Application; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.RadioButton; import javafx.scene.control.ToggleGroup; import javafx.scene.layout.VBox; public class App extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { final ToggleGroup group1 = new ToggleGroup(); RadioButton radio1 = new RadioButton("Emese"); RadioButton radio2 = new RadioButton("Béla"); Button button1 = new Button("Választ"); radio1.setToggleGroup(group1); radio2.setToggleGroup(group1); button1.setOnAction(e -> { String valasztott = ""; if(radio1.isSelected()) { valasztott = "Emese"; }else { valasztott = "Béla"; } System.out.println("Választott: " + valasztott); }); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10, 10, 10, 10)); vbox.getChildren().addAll(radio1, radio2, button1); Scene scene = new Scene(vbox, 300, 250); primaryStage.setScene(scene); primaryStage.show(); } }