Reputation: 23
How can I reference the x-position of the first ball and use that on the second ball?
private List<Ball> createBalls() {
List<Ball> balls = new ArrayList<>();
balls.add(new Ball(Color.BLUE, 600, 400, 20, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.RED, ball(1).get position 1, 500, 13, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.GREEN, 320, 340, 20, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.YELLOW, 50, 400, 50, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.orange, 600, 300, 15, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.CYAN, 320, 340, 10, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.GRAY, 50, 400, 60, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.magenta, 320, 340, 25, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.white, 50, 400, 40, rInt(-15,15), rInt(-15,15)));
balls.add(new Ball(Color.YELLOW, 800, 200, 500, rInt(-15,15), rInt(-15,15)));
return balls;
}
In my ball class I have
public double getPositionX() {
return positionX;
}
public void setPositionX(double positionX) {
this.positionX = positionX;
}
Upvotes: 0
Views: 58
Reputation: 2939
Not sure I understand but to get a value of X (assuming there is a Ball.getX().
then: balls.get(1).getX();
"for the next element position value?"
You can't get the "next element" before you create it. So after you create the Balls loop though the list and apply the "get next X value" logic.
If you show more code and explain what you are trying to do a little more clearly it would help.
Upvotes: 1