Since the GWindow applet is basically in a closed class it is not possible to access the normal PApplet event loop.
In G4P when a button is created it will look for a method in the main applet with the following signature
Code:public void handleButtonEvents(GButton button)
Assuming you have a number of buttons then you need to check to see which button was used and the event type e.g.
Code:public void handleButtonEvents(GButton button) {
if(button == btnUp && button.eventType == GButton.CLICKED)
txfML2.scroll(GTextField.SCROLL_UP);
if(button == btnDown && button.eventType == GButton.CLICKED)
txfML2.scroll(GTextField.SCROLL_DOWN);
if(button == btnRight && button.eventType == GButton.CLICKED)
txfML2.scroll(GTextField.SCROLL_RIGHT);
if(button == btnLeft && button.eventType == GButton.CLICKED)
txfML2.scroll(GTextField.SCROLL_LEFT);
}
This will work for all buttons even if they have been added to another GWindow.
It is also possible for each GUI component (or group of components) to have their own personalised event handler.
All GUI components have a method that can be used to specify their event handler, for instance assume we have a button called
btnUp and we want to add a personalised event handler. We can use the statement
Code:btnUp.addEventHandler(this, "handleUpButtonEvents");
This assumes that you have created the following method
Code:public void handleUpButtonEvents(GButton button){
}
Notice the parameter. All event handlers are expected to have a single parameter of the same type as the GUI component. This is the component that generates the event. In this case btnUp.
Hope this answers your question.