Is it possible to override the constructor for GWinData in G4P?

Hi again!

I was trying to override the constructor for GWinData so that I could create all the controls required for the child window in the GWinData constructor (to maximize encapsulation), but it isn’t working. The program runs, but when I click on the button to hide the child window, I get this error:

The GButton class cannot find this method
	public void exitHandler(GButton button, GEvent event) { /* code */ }

The child window doesn’t get hidden, and I have to press [ESC], which closes both windows. Am I doing something wrong, or just trying to do something that isn’t possible?

Here’s my source code. In the previous version, I was creating the exit button in ‘createOtherWindow()’, in the three lines that are now commented out.

import g4p_controls.*;

class MyWinData extends GWinData {
  GButton btnExit;
  String[] dest = {"Selection 1","Selection 2","Selection 3"};
  int selected = 0;
  public MyWinData() {
    this.btnExit = new GButton(window, 15, 40, 60, 20);
    this.btnExit.addEventHandler(this, "exitHandler");

GButton btnWindow;
GWindow window = null;
//GButton btnExit;

public void setup() {
  size(600, 400, JAVA2D);
  btnWindow = new GButton(this, 15, 40, 60, 20);
  btnWindow.addEventHandler(this, "showHandler");

public void createOtherWindow() {
  window = GWindow.getWindow(this, "Child Window", 20, 40, 400, 200, JAVA2D);
  window.addDrawHandler(this, "windowDraw");
  window.addData(new MyWinData());
  //btnExit = new GButton(window, 15, 40, 60, 20);
  //btnExit.addEventHandler(this, "exitHandler");

public void draw() {
  background(179, 237, 179);

public void showHandler(GButton source, GEvent event) {
  if (window == null) { 
  } else {

public void exitHandler(GButton source, GEvent event) {

public void windowDraw(PApplet app, GWinData data) {
  app.background(179, 237, 179);


1 Like

GWinData is not the apprpriate place to store G4P controls. The purpose of this class is to provide the Gwindow its own data which can be maipulated safely in the windows main event thread. This is shown in the Mandelbrot example.

1 Like