Multiple classes using display() in Netbeans

Outside of the Processing IDE, how do you set up multiple classes that attempt to display all on a single PApplet? Must they all extend PApplet and have a main method like PApplet.main("abc")?

Answers

  • edited June 2017 Answer ✓

    Only the class w/ the settings(), setup() & draw() methods needs to extends PApplet. L-)
    The others request a working PApplet reference as 1 of their constructor's parameter(s): :-B

    "DisplaysOnCanvas.java":

    // forum.Processing.org/two/discussion/22867/
    // multiple-classes-using-display-in-netbeans#Item_1
    
    // GoToLoop (2017-Jun-01)
    
    package org.connor.papplet;
    
    import processing.core.PApplet;
    import static processing.core.PApplet.*;
    
    public class DisplaysOnCanvas {
      public static final int DIAM = 30;
    
      protected final PApplet p;
      public int x, y, c;
    
      public DisplaysOnCanvas(PApplet pa, int px, int py, int col) {
        p = pa;
        x = px;
        y = py;
        c = col;
      }
    
      public void display() {
        p.pushStyle();
    
        p.ellipseMode(CENTER);
        p.noStroke();
        p.fill(c);
        p.ellipse(x, y, DIAM, DIAM);
    
        p.popStyle();
      }
    }
    
  • Slam dunk answer thank you!

  • edited June 2017

    Sorry rookie here; how are you creating the 'pa' PApplet in the main class?

  • attempt to display all on a single PApplet

    The idea is that when you instantiate a DisplaysOnCanvas object, you provide a reference to your current PApplet.... and you do that using the constructor of your class. Here below is what it will look like in Processing, which should be similar to what you are trying to implement in netbeams.

    Kf

    final int kCOL=40;
    DisplaysOnCanvas xCanvas;
    
    void setup(){
       size(600,400);
       xCanvas = new DisplaysOnCanvas(this, width/2,height/2,kCOL);
    }
    
    void draw(){
    
       //Object drawn from main sketch
       ellipse(0,0, DisplaysOnCanvas.DIAM, DisplaysOnCanvas.DIAM);
    
       //Object drawn from your own class and drawing on main sketch
       xCanvas.display();
    }
    
Sign In or Register to comment.