Hi Peter, This was discussed in another thread, but I felt it needed its own dedicated thread.
I want to be able to handle when a user clicks the “x” button to close a GWindow, and also be able to “hide” it using a button if they click the button.
I’ve added a close handler, but it does not trigger when the “x” is clicked on a GWindow. Neither does it trigger when the window is hidden.
Here’s an example:
// Need G4P library
import g4p_controls.*;
// You can remove the PeasyCam import if you are not using
// the GViewPeasyCam control or the PeasyCam library.
import peasy.*;
GWindow window = null;
GButton button0;
public void setup(){
size(480, 320, JAVA2D);
createGUI();
customGUI();
// Place your setup code here
}
public void draw(){
background(230);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
}
void showGWindow() {
if (window == null) {
window = GWindow.getWindow(this, "Title", 100, 100, 200, 100, JAVA2D);
window.setAlwaysOnTop(true);
window.setActionOnClose(G4P.HIDE_WINDOW);//CLOSE_WINDOW//HIDE_WINDOW
//window.addMouseHandler(this, "windowMouse");
//window.addKeyHandler(this, "windowKey");
window.addDrawHandler(this, "windowDraw");
window.addOnCloseHandler(this, "windowClose");
button0 = new GButton(window, 50, 20, 80, 30);
button0.setText("OK");
button0.addEventHandler(this, "button0_click1");
}
else {
window.setVisible(true);
println("not null");
}
}//showGWindow
void windowDraw(PApplet app, GWinData data) {
}
void button0_click1(GButton source, GEvent event) {
window.setVisible(false);
}
public void windowClose(GWindow source){
println("windowClose called!");
}
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
* =========================================================
*/
public void button3_click1(GButton source, GEvent event) { //_CODE_:button3:413930:
println("button3 - GButton >> GEvent." + event + " @ " + millis());
showGWindow();
} //_CODE_:button3:413930:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setMouseOverEnabled(false);
surface.setTitle("Sketch Window");
button3 = new GButton(this, 197, 145, 80, 30);
button3.setText("open win");
button3.addEventHandler(this, "button3_click1");
}
// Variable declarations
// autogenerated do not edit
GButton button3;
What I’d like is to be able to trap for both situations, when the user clicks the “x” on the OS dialog box window, or when the button OK is clicked.
Is there a way to handle this correctly?
Thanks,
Mike