/** * Simulate several bouncing balls */ public void bounce(int numPelotas) { int ground = 400; // position of the ground line ArrayList pelotas = new ArrayList(); myCanvas.setVisible(true); // draw the ground myCanvas.drawLine(50, ground, 550, ground); // crate and show the balls for (int i = 0; i < numPelotas; i++) { pelotas.add(new BouncingBall(50+(i*60), 50, 16, Color.blue, ground, myCanvas)); pelotas.get(i).draw(); } // make them bounce boolean finished = false; int aux = 0; while(!finished) { myCanvas.wait(50); // small delay for(BouncingBall pelota : pelotas) { pelota.move(); } // stop once ball has travelled a certain distance on x axis for (BouncingBall pelota : pelotas){ if (pelota.getXPosition() >= 550){ aux ++; } } if (aux==numPelotas-1) { finished = true; } } for(int i=0; i