我使用 javaFX。我正在尝试为按钮指定事件处理方法。发出错误 Cannot resolve symbol actionOk。老实说,我不明白这是怎么回事。fx:controller 已指定,方法已创建,fxml 文件在这些方法所在的位置看到 EditDialogController(Intellij Idea 看到按钮和字段,我可以双击它们)。在这个有问题的代码旁边是主控制器和主框架,它们是按照图像和相似性制作的,效果很好。告诉我我错过了什么。文件
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="150.0" prefWidth="400.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sample.EditDialogController">
<left>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label text="Full name">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Label text="Phone">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="17.0" />
</VBox.margin>
</Label>
</children>
<BorderPane.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</BorderPane.margin>
</VBox>
</left>
<center>
<VBox minWidth="200.0" prefHeight="200.0" prefWidth="100.0"
BorderPane.alignment="CENTER">
<children>
<TextField fx:id="fieldFullName">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TextField>
<TextField fx:id="fieldPhone">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TextField>
</children>
<BorderPane.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</BorderPane.margin>
</VBox>
</center>
<right>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="buttonOkName" defaultButton="true"
mnemonicParsing="false" onAction="#actionOk" prefHeight="25.0"
prefWidth="51.0" text="OK">
<VBox.margin>
<Insets bottom="5.0" left="25.0" right="5.0" top="5.0" />
</VBox.margin>
</Button>
<Button fx:id="buttonPhoneCalcel" cancelButton="true"
mnemonicParsing="false" text="Cancel">
<VBox.margin>
<Insets bottom="5.0" left="25.0" right="5.0" top="5.0" />
</VBox.margin>
</Button>
</children>
<BorderPane.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</BorderPane.margin>
</VBox>
</right>
</BorderPane>
接下来分别是控制器文件:package sample;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.awt.event.ActionEvent;
public class EditDialogController
{
@FXML
public Button buttonOkName;
@FXML
public Button buttonPhoneCalcel;
@FXML
public TextField fieldFullName;
@FXML
public TextField fieldPhone;
public Person person;
public void actionClose(ActionEvent actionEvent)
{
}
public void setPerson(Person person)
{
this.person = person;
fieldFullName.setText(person.getFullName());
fieldPhone.setText(person.getPhone());
}
public void actionOk(ActionEvent actionEvent)
{
}
}
你的问题是这一行
ActionEvent您从一个包中导入java.awt,您需要ActionEvent的就在包中javafx.event