我是javafx的首发,我正在尝试创建一个可以通过单击按钮存储输入的表单
在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
有没有办法解决这个问题?如果我不必实现功能接口会更好!
发布于 2018-09-29 10:24:51
正确的语法是
String t = Input.getText();
https://stackoverflow.com/questions/-100002792
复制相似问题