G4p Multiple window problem

edited February 2015 in Library Questions

Hi everyone, basically i have a main menu which has 3 buttons to open new window working differently. So far i can add buttons to the created window but these buttons do not response on the click anymore. I am not sure is my way the correct way to do things or anything wrong on the handleButtonEvents method. Can somebody please read my code and tell me what goes wrong?

I cant get the code function working please use this link (http://paste.ofcode.org/uHeGmzY35YvVW25UmeJKF7).

Answers

  • edited February 2015

    The first thing to realise is that for a GWindow the draw handler is the equivalent of Processing's draw() method. In other words it is executed ~60 times a second and is responsible for creating the display.

    In you code you are creating btnGrasp and btnRelease 60 times a second :(

    Ok the solution is to remove the lines creating these buttons from the draw handler so you have

    void wndManualDraw(GWinApplet appc, GWinData data) {
      appc.background(200);
      appc.fill(111);
    }
    

    and create the buttons when you create the window like this

    if (button == btnManual && event == GEvent.CLICKED && wndManual == null) {
      wndManual = new GWindow(this, "Manual Control", 0, 0, 300, 300, false, JAVA2D);
      btnGrasp = new GButton (wndManual.papplet, 0, 0, btnWidth, btnHeight, "Grasp");
      btnRelease = new GButton (wndManual.papplet, 0, btnHeight, btnWidth, btnHeight, "Release");
      wndManual.addDrawHandler(this, "wndManualDraw");
      wndManual.setOnTop(false);
      btnManual.setEnabled(false);
    }
    

    I know these changes because I have tested them. :D

  • Thanks Quark, it works now.

Sign In or Register to comment.