一、只有一个回调方法:
可以先定义一个事件总线,然后在调用方法中直接调用。
如:
1:定义自定义事件
创建一个事件类,用于在组件间传递消息:
public class GeneralEvent extends Event {
public static final EventType<GeneralEvent > INVOKE_GENERL = new EventType<>(Event.ANY, "INVOKE_GENERL");
public GeneralEvent () {
super(INVOKE_GENERL);
}
}
2:在父页面注册事件监听器
在父页面(如 BorderPane
)中添加事件监听:
public class GrandparentController {
public void initialize() {
// 监听自定义事件
borderPane.addEventHandler(GeneralEvent .INVOKE_GENERL, e -> {
handleGrandparentAction();
});
}
private void handleGrandparentActi