I am writing a program to do mass image editing and would like to have the end user select an input and output folder when the program starts.
I tried using selectFolder("Select a input folder:", "inputFolder");
and it opened the folder selection thing, but my code continues to run before a folder is selected, leading to a null error where one of my commands tries acting on the not yet initiated String iPath
Minimized code example:
import java.io.File;
String inputPath;
void setup() {
selectFolder("Select a input folder:", "inputFolder");
CommandIWantToRunAFTERFolderIsSelected(inputPath);
}
void inputFolder(File selection) {
if (selection == null) {
javax.swing.JOptionPane.showMessageDialog(null, "Input Window was closed or the user hit cancel.", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
exit();
} else {
inputPath = selection.toString();
println("User selected " + selection.getAbsolutePath());
}
}
void CommandIWantToRunAFTERFolderIsSelected(String path){
if (path == null){
println("Process crash due to null interperetation");
} else {
println("no crash as command ran after string initiated");
}
}
Running the above code without modification, you will see that the command that interprets the path runs before a file path is selected.
How would I fix this issue