Why are my objects not being called on the second window?

edited November 2016 in Questions about Code
//So I am trying to build a GUI to control my main display. I can call things like ellipse() but not my own classes such as my Button classes.


    ControlPanel controlP;
    ButtonOne buttonOne;

    boolean buttOne, flag;

    float buttRad = 33/2, buttX, buttY;

    public void settings() {
      size(500, 500, P3D);
      buttonOne = new ButtonOne();
    }

    void setup() {
      surface.setTitle("MainDisplay");


      controlP = new ControlPanel();
      buttOne = false;
      flag = false;
    }

    void draw() {
      if (buttOne) {
        background(255);
        buttonOne.buttOn();
      } else {
        background(0);
        buttonOne.buttOff();
      }
      if (!flag) {
        surface.setLocation(0, 0);
        flag = true;
      }
    }

    void mousePressed() {
      float buttDist = dist(mouseX, mouseY, buttX, buttY);
      buttX = width/2;
      buttY = height/2;
      if (buttDist < buttRad) {
        buttOne = !buttOne;
      }
    }

    class ControlPanel extends PApplet {
    ButtonTwo buttonTwo;
      ControlPanel() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
        surface.setLocation(0, 550);
      }

      void settings() {
        size(500, 500, P3D);
        buttonTwo = new ButtonTwo();
      }

      void setup() {

      }

      void draw() {
          if (buttOne) {
          background(0);
          buttonTwo.buttTwoOn();
        } else {
          background(255);
          buttonTwo.buttTwoOff();
        }
        //if (!flag) {
        //  surface.setLocation(700, 200);
        //  flag = true;
        //}
      }

      void mousePressed() {
        float buttDist = dist(mouseX, mouseY, buttX, buttY);
        buttX = width/2;
        buttY = height/2;
        if (buttDist < buttRad) {
          buttOne = !buttOne;
        }
      }
    }

    class ButtonOne {


      ButtonOne() {
      }

      void buttOn() {
        ellipseMode(CENTER);
        noStroke();
        fill(0);
        ellipse(width/2, height/2, 33, 33);
      }

      void buttOff() {
        ellipseMode(CENTER);
        noStroke();
        fill(255);
        ellipse(width/2, height/2, 33, 33);
      }
    }

    class ButtonTwo {

      ButtonTwo() {
      }

      void buttTwoOn() {
        ellipseMode(CENTER);
        noStroke();
        fill(255);
        ellipse(width/2, height/2, 33, 33);
      }

      void buttTwoOff() {
        ellipseMode(CENTER);
        noStroke();
        fill(0);
        ellipse(width/2, height/2, 33, 33);
      }
    }

Answers

  • Only 1 PApplet can use an OpenGL-based renderer! [-X

  • That is good to know. I still have the same issue when removing the renderer altogether. Any class I write fails to call on the second window.

    Additionally, how does one use OpenGL based renderer on multiple windows?

  • Answer ✓

    Like I said, only 1 can use an OpenGL renderer (P2D & P3D).
    All the others go w/ JAVA2D instead.
    I guess 1 can be FX2D too. :-bd

  • Thank you! That is very helpful ...

    why do you suppose my objects won't call on my additional window?

  • Answer ✓

    That's a diff. matter. You should post your most updated code too.
    Also look up old solutions for runSketch():
    https://forum.Processing.org/two/discussions/tagged?Tag=papplet.runsketch()

  • Thank you @GoToLoop!

    Figured out where my problem was ... you can see my edits in ButtonTwo class and Control Panel class.

        ControlPanel controlP;
        ButtonOne buttonOne;
    
        boolean buttOne, flag;
    
        float buttRad = 33/2, buttX, buttY;
    
        public void settings() {
          size(500, 500, P3D);
          buttonOne = new ButtonOne();
        }
    
        void setup() {
          surface.setTitle("MainDisplay");
    
    
          controlP = new ControlPanel();
          buttOne = false;
          flag = false;
        }
    
        void draw() {
          if (buttOne) {
            background(255);
            buttonOne.buttOn();
          } else {
            background(0);
            buttonOne.buttOff();
          }
          if (!flag) {
            surface.setLocation(0, 0);
            flag = true;
          }
        }
    
        void mousePressed() {
          float buttDist = dist(mouseX, mouseY, buttX, buttY);
          buttX = width/2;
          buttY = height/2;
          if (buttDist < buttRad) {
            buttOne = !buttOne;
          }
        }
    
    class ControlPanel extends PApplet {
    ButtonTwo buttonTwo;
    
      ControlPanel() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
        surface.setLocation(0, 550);
      }
    
      void settings() {
        size(500, 500);
    
      }
    
      void setup() {
        buttonTwo = new ButtonTwo(this);
      }
    
      void draw() {
        if (buttOne) {
          background(0);
          buttonTwo.buttTwoOn();
        } else {
          background(255);
          buttonTwo.buttTwoOff();
        }
        //if (!flag) {
        //  surface.setLocation(700, 200);
        //  flag = true;
        //}
      }
    
      void mousePressed() {
        float buttDist = dist(mouseX, mouseY, buttX, buttY);
        buttX = width/2;
        buttY = height/2;
        if (buttDist < buttRad) {
          buttOne = !buttOne;
        }
      }
    }
    
    class ButtonOne {
    
    
          ButtonOne() {
          }
    
          void buttOn() {
            ellipseMode(CENTER);
            noStroke();
            fill(0);
            ellipse(width/2, height/2, 33, 33);
          }
    
          void buttOff() {
            ellipseMode(CENTER);
            noStroke();
            fill(255);
            ellipse(width/2, height/2, 33, 33);
          }
        }
    
    public class ButtonTwo {
    
      final PApplet p;
    
      ButtonTwo(PApplet win2) {
        p = win2;
      }
    
      void buttTwoOn() {
        p.ellipseMode(CENTER);
        p.noStroke();
        p.fill(255);
        p.ellipse(width/2, height/2, 33, 33);
      }
    
      void buttTwoOff() {
        p.ellipseMode(CENTER);
        p.noStroke();
        p.fill(0);
        p.ellipse(width/2, height/2, 33, 33);
      }
    }
    
Sign In or Register to comment.