# Multiple window with user input

**URL:** <https://discourse.processing.org/t/multiple-window-with-user-input/25515>\
**Category:** Coding Questions\
**Created:** [November 18, 2020, 4:18pm UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515 "2020-11-18T16:18:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [November 18, 2020, 4:18pm UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515/1 "2020-11-18T16:18:18Z")

</div>

Hi all!

I am trying to make a simple GUI with an option menu so that when a button is pressed, a second window opens and waits for the user to click on a button of that second window, before closing it and returning to the main window. When the second window is opened the user should not be able to interact with the main window

I was trying to modify the sketch from the examples on Multiple Windows but I getting an error that I can’t fix for now.

Any advice is welcome!

```auto
// Based on code by GeneKao (https://github.com/GeneKao)

ChildApplet child;

Button b_Parent, b_Child;

void settings() {
  size(320, 240, P2D);
  smooth();
}

void setup() {
  surface.setTitle("Main sketch");
  b_Parent = new Button(this);
 
}

void draw() {
  background(123);
  b_Parent.display();
}

void mousePressed(){
  if(b_Parent.isOver()) child = new ChildApplet();
}

/ ********* /
/* CHILD */
/ ********* /

class ChildApplet extends PApplet {
  //JFrame frame;
  
  public ChildApplet() {
    super();
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  public void settings() {
    size(400, 400, P2D);
    smooth();
  }
  public void setup() { 
    surface.setTitle("Child sketch");
    b_Child = new Button(this);
  }

  public void draw() {
    background(0);
    fill(255,0,0);
    b_Child.display();
  }
  
  void mousePressed(){
   //if(b_Child.isOver()) exit(); 
  }
}

class Button{
  PApplet parent;
  color C;
  
  Button(PApplet parent){
    this.parent = parent;
  }
  
  void display(){
    if(isOver()) C=color(0,255,0);
    else C = color(255,0,0);
    fill(C);
    rect(parent.width/2, parent.height/2, 50,50);
  }
  
  boolean isOver(){
    return (parent.mouseX > parent.width/2 && parent.mouseX < parent.width/2+50 && 
            parent.mouseY > parent.height/2 && parent.mouseY < parent.height/2+50);
  }
}

```

Thanks in advance!  
Best regards

---

<div class="post-metadata">

**Author:** ![Piko](https://avatars.discourse-cdn.com/v4/letter/p/71c47a/32.png) [@Piko](https://discourse.processing.org/u/Piko)\
**Post date:** [November 18, 2020, 8:23pm UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515/2 "2020-11-18T20:23:52Z")

</div>

Why not use the G4P GUI library?

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [November 19, 2020, 8:42am UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515/3 "2020-11-19T08:42:10Z")

</div>

Hi,

> [@MiguelSanches](#):
>
> I getting an error that I can’t fix for now.

Can you show the error you have?

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [November 19, 2020, 9:09am UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515/4 "2020-11-19T09:09:29Z")

</div>

Hi @josephh

The error is as follows:

org.eclipse.jdi.TimeoutException: Timeout occurred while waiting for packet 1288.  
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:187)  
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:198)  
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:192)  
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:227)  
at org.eclipse.jdi.internal.ObjectReferenceImpl.invokeMethod(ObjectReferenceImpl.java:437)  
at processing.mode.java.runner.Runner.findException(Runner.java:844)  
at processing.mode.java.runner.Runner.reportException(Runner.java:789)  
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:709)  
at processing.mode.java.runner.Runner$2.run(Runner.java:599)  
ArrayIndexOutOfBoundsException: 66  
com.sun.jdi.VMDisconnectedException: Got IOException from Virtual Machine  
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:180)  
at org.eclipse.jdi.internal.connect.PacketReceiveManager.getReply(PacketReceiveManager.java:198)  
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:192)  
at org.eclipse.jdi.internal.MirrorImpl.requestVM(MirrorImpl.java:227)  
at org.eclipse.jdi.internal.ObjectReferenceImpl.invokeMethod(ObjectReferenceImpl.java:437)  
at processing.mode.java.runner.Runner.findException(Runner.java:844)  
at processing.mode.java.runner.Runner.reportException(Runner.java:789)  
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:709)  
at processing.mode.java.runner.Runner$2.run(Runner.java:599)  
ArrayIndexOutOfBoundsException: 66

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [November 19, 2020, 9:12am UTC](https://discourse.processing.org/t/multiple-window-with-user-input/25515/5 "2020-11-19T09:12:03Z")

</div>

I will look into that.

Thanks
