Currently learning JavaFX and its capabilities.
I used SceneBuilder to create a TextField and button. I want to print what the user typed in the TextField when the button is clicked.
Why does this not print the values that the user entered into the TextBox?
public void generateButtonClicked() {
TextField forehandWinner = new TextField();
forehandWinner.getText();
System.out.println(forehandWinner);
FXML Button Code:
<Button mnemonicParsing="false" onAction="#generateButtonClicked" text="Generate Statistics" />
FXML TextField Code:
<TextField id="forehandWinner" fx:id="forehandWinner" alignment="CENTER" promptText="Forehand Winners">
答案 0 :(得分:1)
@FXML private TextField forehandWinner;
public void generateButtonClicked(ActionEvent event)
在generateButtonClicked方法中,执行以下操作:
public void generateButtonClicked(ActionEvent event){ 的System.out.println(forehandWinner.getText()); }