我想知道有关从孩子向父母发送事件的信息。 我编写了这段代码,如果选择目录,则可以在ImageView的目录中看到第一张图片。
按下按钮并选择目录后,我想将路径发送到ParentController。 但是,现在我无法发送,因为在创建窗口时会调用getcurrentPath()。
ParentController
@FXML private Button openDirButton;
@FXML private ImageView mainImageView;
@FXML
public void initialize(URL location,ResourceBundle resources) {
// Choosing Directory Button
opendirectoryButton ODB = new opendirectoryButton();
ODB.getDirSetImageSetListView(openDirButton,mainImageView);
String currentPath = ODB.getcurrentPath();
System.out.println(currentPath); // null
ChildController
public class opendirectoryButton {
public static String path;
public Button getDirSetImageSetListView(Button button,ImageView imageView) {
button.setOnaction(actionEvent -> {
// This is a class I made
DirectoryChoose DC = new DirectoryChoose();
// Get a Directory Path
path = DC.getPath();
// Get a list of path of images
imageList = DC.getimagelist(path);
image = new Image("file:///" + path + File.separator + imageList.get(0));
imageView.setImage(image);
});
return button;
}
public String getcurrentPath() {
return path;
}
}