JavaFX:MenuItem触发鼠标事件

在JavaFX中,菜单是控件Menu,菜单项是MenuItem,不同于按钮控件Button,控件Button可以使用枚举MouseEvent.MOUSE_CLICKED触发按钮事件。菜单项控件MenuItem使用枚举ActionEvent.ACTION触发事件。下面分别使用方法setOnAction和方法addEventHandler注册菜单项事件。

openFileItem.setOnAction(event -> mainFrameHandle.chooseFiles());

quitItem.addEventHandler(ActionEvent.ACTION,
    event ->mainFrameHandle.exitApplication(event)
);

你可能感兴趣的:(Java,JavaFX,开发语言,JavaFX,Java)