【发布时间】:2015-04-26 14:52:31
【问题描述】:
我是 JavaFX 新手,目前在处理不同包中的类的 onAction 事件时遇到了一些问题。
这是包树:
这是不工作的代码示例:
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane fx:controller="GUIController.AccueilController"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
...
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="4">
<Button text="Se connecter" onAction="#handleSubmitButtonAction"/>
</HBox>
...
</GridPane>
错误发送者:
onAction="#handleSubmitButtonAction"
说:“处理程序方法不可访问。公开,或用@FXML注释”
这里是 AccueilController.java 文件:
package GUIController;
import java.awt.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.text.Text;
public class AccueilController {
@FXML private Text actiontarget;
@FXML protected void handleSubmitButtonAction(ActionEvent event) {
actiontarget.setText("Sign in button pressed");
}
}
如您所见,添加了@FXML标签,所以我不知道问题出在哪里。可能有点笨,但我真的想不通。
顺便说一句,没有 onAction 行,代码运行良好。
谢谢你们!
【问题讨论】:
-
将受保护的 void handleSubmitButtonAction 更改为公共方法
-
这不会改变任何东西。
标签: java javafx controller fxml