Can't add elements to an arraylist?

My Circle class was absolutely identical to yours besides mine using this.x and this.y instead of x and y for the display() method (not that I think it makes a difference)
However, while keyPressed didn’t work, using mousePressed || keyPressed fixed the issue, and after that, simply putting “keyPressed” was working again, so I’m confused

Here’s another one where it doesn’t work properly, it’s basically a graph you can put points on by simply clicking (graph is just there to draw the background and PrimeChecker checks whether a number’s polar coordinates are prime, they’re not used here)

//
ArrayList<Point> pointArray = new ArrayList();

int scale;
int numberOfPoints;
boolean checkPrime;
boolean placePoint = true;

void setup()
{
  numberOfPoints = 400;
  scale = 50;
  checkPrime = true;
  fullScreen();
}

void draw()
{
  background(0);
  translate(width/2, height/2);
  GraphDrawer graph = new GraphDrawer(scale);
  graph.circles();
  graph.graph();
  
  if(mousePressed || keyPressed)
  {
    Point test = new Point(mouseX, mouseY);
    pointArray.add(test);
    println(pointArray.size());
  }
  
  Point plotting = new Point(100, 100, 10);
  plotting.plotter(numberOfPoints, scale, checkPrime);
  
  for(Point points : pointArray)
    {
    
      points.display();
      println("test");
    }
}
//
class Point
{
  
  ArrayList<Point> pointArray = new ArrayList();
  
  float radius;
  float angle;
  float x;
  float y;
  int r;
  int numberOfPoints;
  int scale;
  boolean isPrime;
  boolean checkPrime;
  
  int pouet = 0;
  
  //Constructor for polar coordinates
  Point(float _radius, float _angle)
  {
    radius = _radius;
    angle = _angle;
  }
  
  //Constructor for carthesian coordinates
  Point(float _x, float _y, int _radius)
  {
    x = _x;
    y = _y;
    radius = _radius;
  }
  
  //Display for carthesian coordinates
  void display()
  {
   //Color and fill setup
   noStroke();   
   fill(255, 10, 10);
   //Plotting our point on the graph
   println(x);
   circle(x, y, radius);
  }

Thanks a lot for your help !

1 Like