I'm learning how to use javafx, along with scenebuilder by creating a very basic calculator but I've come across a problem where it's hard for me to find a way to not have a seperate function for each button. I need to know if there's a way for a button to change a variable or give arguments to the action event method that the button is linked to so I don't need seperate methods for each button to call another function. This is an example of what I'm working with.
@FXML
private Button one;
private Button two;
//both buttons are linked to NumChange
private void NumChange(ActionEvent e) {
//update the number to preform an operation with here
}
How do I have all the number buttons use the same function but send it arguments so it can do different things?
All of the answers I've found involve using getting the text of the button, however my calculator is weird and I'm having the spelled out word on them so I can't do that, what can I do?
one.setOnAction(event -> NumChange(...));
two.setOnAction(event -> NumChange(...));
– Sublet