I have a button that adds its name to a TextArea. I want the button to hold a double that also gets displayed in the text area but is not displayed on the button itself.
Here is my MainMenuController where the TextArea is
@FXML TextArea txtReceipt;
@FXML
public void buttonHandler(ActionEvent event) {
Button button = (Button) event.getSource();
txtReceipt.appendText ((String) button.getText() + "\n");
}
At first, I extended the Button class to include a double. However, JavaFX does not recognize this as a control. I then made a class to hold a button to no avail.
import javafx.scene.control.Button;
/**
*
* @author David
*/
public class NumButton extends Button{
double cost;
private void setCost(double cost)
{
this.cost = cost;
}
}
Can anyone provide guidance on how to achieve this? I am thinking that perhaps
Button button = (Button) event.getSource();
txtReceipt.appendText ((String) button.getText() + "\n");
should be
NumButton numButton = (Button) event.getSource();
txtReceipt.appendText ((String) numButton.getText() + numButton.cost + "\n");