简体   繁体   中英

JavaFX - Which method of event listener is more efficient?

I just started using event listener in JavaFX . I stumbled upon two methods for the same purpose. Any advantage of one or the other?

 test1.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                    System.out.print("PPT");
            }
        });

and

    test1 .selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov,
            Boolean old_val, Boolean new_val) {
            log("ggggggg");
        }
    });

Also test1 is the name of the checkbox

两种方法之间的效率差异将基本可以忽略不计-只需选择最适合您应用程序功能且最容易理解的方法即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM