import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.CheckBox; import javafx.stage.Stage; public final class SelectionHandler implements EventHandler { private Stage stage; private CheckBox checkBox; public SelectionHandler(Stage stage, CheckBox checkBox) { this.stage = stage; this.checkBox = checkBox; } @Override public void handle(ActionEvent e) { if (this.checkBox.isSelected()) { this.stage.close(); } } }