JAVAFX按钮动作调用其他类的函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21116585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:42:10 来源:igfitidea点击:
JAVAFX button action to call a function of other class
提问by TomJ
I am creating a project using javafx. I am using netbeans IDE. I had created many classes. When a button is pressed, a function from other class has to be worked. How to make it working ?
我正在使用 javafx 创建一个项目。我正在使用 netbeans IDE。我创建了很多类。当按下按钮时,必须使用其他类的函数。如何让它工作?
采纳答案by assylias
With Java 8:
使用 Java 8:
button.setOnAction(e -> anInstanceOfYourOtherClass.yourMethod());
Prior to Java 8:
在 Java 8 之前:
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
anInstanceOfYourOtherClass.yourMethod();
}
});