Fixed the problem, thanks for all the help c:
To track iceCream selected, simply add new field iceCream. And assign a value to it once it's selected. Do the same with you toppingsCost:
public class FXMLDocumentController implements Initializable {
private String iceCream;
private double toppingsCost;
....
private void handleButtonSaving(ActionEvent event) {
if(vanilla.isSelected()) {
iceCream = "Vanilla";
System.out.println(iceCream);
}
if(chocolate.isSelected()) {
iceCream = "Chocolate";
System.out.println(iceCream);
}
...
private void handleButtonCalculateCost(ActionEvent event) {
double myTotal = 0.0;
myTotal += retrieveIceCreamCost();
toppingsCost = retrieveToppingsCost();
myTotal += toppingsCost;
...
Consider how RadioButtons are grouped by a ToggleGroup. In code:
final ToggleGroup icecream = new ToggleGroup();
RadioButton rb1 = new RadioButton("Vanilla");
rb1.setToggleGroup(icecream);
rb1.setSelected(true);
RadioButton rb2 = new RadioButton("Chocolate");
rb2.setToggleGroup(icecream);
RadioButton rb3 = new RadioButton("Strawberry");
rb3.setToggleGroup(icecream);
You can handle all selection by the ToggleGroup component.
RadioButton selected = (RadioButton) icecream.getSelectedToggle();
ObservableList<Toggle> radioButtons = icecream.getToggles();
Writing the selected radio button's label (say "Vanilla") and later reading "Vanilla" and looping through all radioButtons to select the matching one is not too circumstantial.