The point with using a function mousePressed() instead of the variable mousePressed is
very important.
remark
-
please note that with selectOutput you choose a file to save to.
-
maybe to load you want selectInput which is a similar command
Sketch
Anyway, you can use state to distinguish the different phases:
int state = 0;
String pathMy="";
void setup() {
size(960, 540);
background(111);
}
void draw() {
background(111);
switch(state) {
case 0:
text("please click the mouse to choose a file", 66, 66);
break;
case 1:
text("please choose a file", 66, 66);
break;
case 2:
text ("You chose "
+ pathMy
+ "\n\n\n\n\n\n\n\n\nClick the mouse to start again.", 66, 66);
break;
default:
//Error
exit();
break;
}//switch
}//func
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
state = 0;
} else {
println("User selected " + selection.getAbsolutePath());
pathMy=selection.getAbsolutePath();
state = 2;
}
}
void mousePressed() {
switch(state) {
case 0:
selectOutput("Select a file to write to:", "fileSelected");
state=1;
break;
case 1:
//ignore
break;
case 2:
// reset
state = 0;
break;
default:
//Error
exit();
break;
} //switch
} //func
//