I'm working on a javafx quiz, doing something like kahoot
I've got 4 radio buttons, with test option each, which are taken from the array of options
array of options is just an array with 4 options, which are than given to my 4 buttons, but the oder is shuffled so I need to retrieve the index of the button that was clicked
to do so I need setter and getter methods for retrieving the index of chosen RadioButton
Please help me
I have no idea how to return index of chosen element from the button
ToggleGroup toggleGroup = new ToggleGroup();
rdBtn1.setToggleGroup(toggleGroup);
rdBtn2.setToggleGroup(toggleGroup);
rdBtn3.setToggleGroup(toggleGroup);
rdBtn4.setToggleGroup(toggleGroup);
RadioButton[] radioButtons = {rdBtn1, rdBtn2, rdBtn3, rdBtn4};
if (getIndex() != -1) {
int j = getIndex();
for (int i = 0; i < 4; i++) {
radioButtons[i].setSelected(i == j);
}
}
rdBtn.setOnAction(e -> {
setIndex(0);
int index = getIndex();
String userChoice = getOptionAt(index);
});
setIndex(0); getIndex();
what I really need is these two methods that will get and set index of the button after it has been clicked
