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")?


  • 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


    // 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.ellipse(x, y, DIAM, DIAM);
  • 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.


    final int kCOL=40;
    DisplaysOnCanvas xCanvas;
    void setup(){
       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
Sign In or Register to comment.