Closing G4P Window
in
Contributed Library Questions
•
7 months ago
Hi everyone.
I have a question about closing a GWindow.
I have read through https://forum.processing.org/topic/g4p-library-window-close and https://forum.processing.org/topic/closing-g4p-windows-and-menus and some others yesterday, and already know about the setActionOnClose method.
My issue however is a little different. Admittedly, I have not yet tried adding the closeWindow sub to my program as was suggested in the second post I reffered to, since it was mentioned that the functionality will be built in and I believe I'm using it.
Here is my issue. I need a popup to ask for some details when the program starts to create a data file. I'm playing with the example (WindowsStarter) at the moment, and made the following adjustment to the code to try and close a window with code:
void windowMouse(GWinApplet appc, GWinData data, MouseEvent event) {
MyWinData data2 = (MyWinData)data;
if ((appc.mouseX > 15) | (appc.mouseY > 15)) {
switch(event.getAction()) {
case MouseEvent.PRESS:
data2.sx = data2.ex = appc.mouseX;
data2.sy = data2.ey = appc.mouseY;
data2.done = false;
break;
case MouseEvent.RELEASE:
data2.ex = appc.mouseX;
data2.ey = appc.mouseY;
data2.done = true;
break;
case MouseEvent.DRAG:
data2.ex = appc.mouseX;
data2.ey = appc.mouseY;
break;
}
}
else {
switch (event.getAction()) {
case MouseEvent.CLICK:
appc.owner.close();
println("Cheers - " + millis());
}
}
}
This does exactly what I expected it to do, however, I get a NullPointerException error after the println. This seems to occur in the handleDraw method, which is weird since the GWindow.close should release all the handlers if I'm not mistaken. This also only appears to happen once, I assume the very next call after I closed the window, and after that it actually did release all the handlers.
Any ideas? Timing issue with my old celeron laptop?
I tried to add a public void handleDraw, but the main window never opens then.
Any help would be appreciated.
Regards
Jan-Daniël de Villiers
I have a question about closing a GWindow.
I have read through https://forum.processing.org/topic/g4p-library-window-close and https://forum.processing.org/topic/closing-g4p-windows-and-menus and some others yesterday, and already know about the setActionOnClose method.
My issue however is a little different. Admittedly, I have not yet tried adding the closeWindow sub to my program as was suggested in the second post I reffered to, since it was mentioned that the functionality will be built in and I believe I'm using it.
Here is my issue. I need a popup to ask for some details when the program starts to create a data file. I'm playing with the example (WindowsStarter) at the moment, and made the following adjustment to the code to try and close a window with code:
void windowMouse(GWinApplet appc, GWinData data, MouseEvent event) {
MyWinData data2 = (MyWinData)data;
if ((appc.mouseX > 15) | (appc.mouseY > 15)) {
switch(event.getAction()) {
case MouseEvent.PRESS:
data2.sx = data2.ex = appc.mouseX;
data2.sy = data2.ey = appc.mouseY;
data2.done = false;
break;
case MouseEvent.RELEASE:
data2.ex = appc.mouseX;
data2.ey = appc.mouseY;
data2.done = true;
break;
case MouseEvent.DRAG:
data2.ex = appc.mouseX;
data2.ey = appc.mouseY;
break;
}
}
else {
switch (event.getAction()) {
case MouseEvent.CLICK:
appc.owner.close();
println("Cheers - " + millis());
}
}
}
This does exactly what I expected it to do, however, I get a NullPointerException error after the println. This seems to occur in the handleDraw method, which is weird since the GWindow.close should release all the handlers if I'm not mistaken. This also only appears to happen once, I assume the very next call after I closed the window, and after that it actually did release all the handlers.
Any ideas? Timing issue with my old celeron laptop?
I tried to add a public void handleDraw, but the main window never opens then.
Any help would be appreciated.
Regards
Jan-Daniël de Villiers
1