Multiple window with user input

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!

// 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

Why not use the G4P GUI library?

Hi,

Can you show the error you have?

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

I will look into that.

Thanks