ArrayList of ArrayLists (dynamic 2D array) of custom class

Hey Chrisir
any reference material on how to use arraylists within objects ?
Thanks

1 Like

your question is very broad, but you can treat an ArrayList within a class just normal:

come back for more questions please :wink:


Circle myCircle = new Circle();  // make object from class 

void setup() {
  size(800, 800);
}// function setup()

void draw() {
  background(0);
  myCircle.display(); // use method in the class 

  noFill();
  stroke(255);
  // use ArrayList in the class (not so nice)
  rect(myCircle.points.get(2).x, myCircle.points.get(2).y,
    30, 30);
  //
}// function draw()

// =====================================================================================

class Circle {

  ArrayList<PVector> points = new ArrayList();

  // constr
  Circle () {
    points.add(new PVector(123, 234));
    points.add(new PVector(143, 334));
    points.add(new PVector(223, 434));
  }// constr

  void display() {
    fill(255);
    for (PVector pv : points) {
      ellipse(pv.x, pv.y, 12, 12);
    } // for
  }//method
  //
}//class
//