# \[SOLVED\] G4P options in second window problem

**URL:** <https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552>\
**Category:** Libraries\
**Created:** [October 17, 2018, 9:26am UTC](https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552 "2018-10-17T09:26:51Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [October 17, 2018, 10:59am UTC](https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552/3 "2018-10-17T10:59:54Z")

</div>

Also in your second post you are setting an option true BEFORE adding it to the toggle group, Only use `setSelected` AFTER all the options have been added to the option group. (You didn’t do this in your first post).

In this code I have corrected the mistakes in your second post and shown how you can add separate event handlers for both sets of opuions.

```auto
import g4p_controls.*;
GOption option0, option1;
GOption woption0, woption1;

GWindow[] window;

public void setup() {
  size(200, 100);
  createGUI();
  createWindows();
}

public void draw() {
  background(100, 100, 200);
}

public void createGUI() {
  int posX = 40, posY =20, dposY = 20;
  GToggleGroup tg = new GToggleGroup();

  option0 = new GOption(this, posX, posY+0*dposY, 80, 24, "A");
  option0.setTextAlign(null, GAlign.BOTTOM);

  option1 = new GOption(this, posX, posY+1*dposY, 80, 24, "B");
  option1.setTextAlign(null, GAlign.BOTTOM);

  tg.addControls(option0, option1); // Group the option buttons
  option1.setSelected(true); // Must set one of the options true

  option0.addEventHandler(this, "option_clicked");
  option1.addEventHandler(this, "option_clicked");
}

public void option_clicked(GOption source, GEvent event) { 
  if (source == option0) { 
    println("option0");
  } //option1.setSelected(false);
  if (source == option1) { 
    println("option1");
  } //option0.setSelected(false);
} 

public void win_option_clicked(GOption source, GEvent event) { 
  if (source == woption0) { 
    println("woption0");
  } //option1.setSelected(false);
  if (source == woption1) { 
    println("woption1");
  } //option0.setSelected(false);
} 

// _______________________________________________________________________
public void createWindows() {

  window = new GWindow[1];
  // for (int i = 0; i < 1; i++) {
  // window[i] = GWindow.getWindow(this, " ", 70+i*220, 160+i*50, 400, 400, JAVA2D);
  // }
  // menu window config
  window[0] = GWindow.getWindow(this, "window2", 70, 160, 200, 100, JAVA2D);
  window[0].setActionOnClose(G4P.CLOSE_WINDOW);
  //window[0].addOnCloseHandler(this, "windowClosing");
  //window[0].addData(new MyWinData());
  window[0].addDrawHandler(this, "windowDraw");
  //window[0].addMouseHandler(this, "windowMouse");
  //window[0].addKeyHandler(this, "windowKey");

  int posX = 40, posY =20, dposY = 20;
  GToggleGroup wtg = new GToggleGroup();

  woption0 = new GOption(window[0], posX, posY+0*dposY, 80, 24, "wA");
  woption0.setTextAlign(null, GAlign.BOTTOM);

  woption1 = new GOption(window[0], posX, posY+1*dposY, 80, 24, "wB");
  woption1.setTextAlign(null, GAlign.BOTTOM);

  wtg.addControls(woption0, woption1); // Group the option buttons

  woption1.setSelected(true); // Must set one of the options true

  woption0.addEventHandler(this, "win_option_clicked");
  woption1.addEventHandler(this, "win_option_clicked");
}

// _______________________________________________________________________
synchronized public void windowDraw(PApplet appc, GWinData data) {
  // MyWinData data2 = (MyWinData)data;
  appc.background(200, 200, 0);
}

```

---

_[View the full topic](https://discourse.processing.org/t/solved-g4p-options-in-second-window-problem/4552)._
