-1
我是javafx的入門者。我正在嘗試創建一個可以通過單擊按鈕存儲輸入的表單。但是,它有錯誤,我無法繼續。 這裏是我的代碼:帶場景生成器的javafx無法從textField中獲取文本
在FXML文件:
<VBox prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ass.InputDataController">
<children>
<Label text=" Input" />
<TextField id="Input" fx:id="Input" onAction="#handleButtonAction" />
<Button fx:id="enter" onAction="#handleButtonAction" prefHeight="57.0" prefWidth="707.0" text="Enter" />
</children>
</VBox>
在InputDataController.java:
public class InputDataController implements Initializable {
@FXML
private TextField Input;
@FXML
private void handleButtonAction(ActionEvent event) {
String t = Input->getText();
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
錯誤說:
error: incompatible types: String is not a functional interface
String t = Input->getText();
我試圖實現另一個功能:
@FunctionalInterface
interface String {
String getText(TextField t);
}
但它仍然指出:
error: cannot find symbol
有沒有解決這個問題的方法?如果我不需要實現一個功能接口,會更好!