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

**URL:** https://discourse.processing.org/t/is-it-possible-to-override-the-constructor-for-gwindata-in-g4p/20756
**Category:** Libraries
**Created:** [May 11, 2020, 7:55pm UTC](https://discourse.processing.org/t/is-it-possible-to-override-the-constructor-for-gwindata-in-g4p/20756 "2020-05-11T19:55:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)
#### Post date: [May 11, 2020, 7:55pm UTC](https://discourse.processing.org/t/is-it-possible-to-override-the-constructor-for-gwindata-in-g4p/20756/1 "2020-05-11T19:55:13Z")

</div>

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:

```auto
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.

```auto
import g4p_controls.*;

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

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

public void setup() {
  size(600, 400, JAVA2D);
  G4P.setGlobalColorScheme(GCScheme.GREEN_SCHEME);
  btnWindow = new GButton(this, 15, 40, 60, 20);
  btnWindow.setText("Show");
  btnWindow.addEventHandler(this, "showHandler");
}

public void createOtherWindow() {
  window = GWindow.getWindow(this, "Child Window", 20, 40, 400, 200, JAVA2D);
  window.setVisible(false);
  window.setActionOnClose(G4P.KEEP_OPEN);
  window.addDrawHandler(this, "windowDraw");
  window.setVisible(true);
  window.addData(new MyWinData());
  //btnExit = new GButton(window, 15, 40, 60, 20);
  //btnExit.setText("Exit");
  //btnExit.addEventHandler(this, "exitHandler");
}

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

public void showHandler(GButton source, GEvent event) {
  if (window == null) { 
    createOtherWindow();
  } else {
    window.setVisible(!(window.isVisible()));
  }
  btnWindow.setEnabled(false);
}

public void exitHandler(GButton source, GEvent event) {
  window.setVisible(false);
  btnWindow.setEnabled(true);
}

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

```

Thanks.

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [May 11, 2020, 9:22pm UTC](https://discourse.processing.org/t/is-it-possible-to-override-the-constructor-for-gwindata-in-g4p/20756/2 "2020-05-11T21:22:48Z")

</div>

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.
