最初のボールのx位置を参照して、それを2番目のボールで使用するにはどうすればよいですか? 。balls.get(1).getX();
配列リストの特定の要素を変更する
:私のボールのクラスでは
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;
}
私は
public double getPositionX() {
return positionX;
}
public void setPositionX(double positionX) {
this.positionX = positionX;
}
"次の要素位置値のX位置値の位置値?"何? – Kayaman
私は以前のボールの 'x'ポジションに' x'ポジションを加算する方法を探していると思います。そのためには、以前のボールを変数 'Ball prev = new Ball(Color.BLUE、600、400、20、rInt(-15,15)、rInt(-15,15)')に保存する必要があります。 Ballクラスの 'X position'を返す' getPositionX() 'を持っていると仮定して、' prev.getPositionX() 'のようにします。 – Samundra
あなたの質問は明確に再構成されていません。 – Ravikumar