Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.     public void bounce(int numberOfBalls)    {
  2.         int ground = 400;   // position of the ground line
  3.  
  4.         myCanvas.setVisible(true);
  5.         ArrayList<BouncingBall> balls = new ArrayList<BouncingBall>(numberOfBalls);
  6.         Dimension cSize = myCanvas.getSize();
  7.         // draw the ground
  8.         myCanvas.drawLine(50, ground, 550, ground);
  9.         // crate and show the balls
  10.        for(int i=0;i<numberOfBalls;i++) {
  11.            balls.add(new BouncingBall(0, 0, 16, new Color((int)(Math.random()*Math.pow(256,3))), 24, myCanvas));
  12.         }
  13.  
  14.        dBalls:while(true) {
  15.             myCanvas.wait(50);          // small delay
  16.             for (int i=0;i<numberOfBalls;i++) {
  17.                 balls.get(i).move();                
  18.                 if(balls.get(i).getXPosition() >= 550) {
  19.                     break dBalls;
  20.                 }
  21.             }
  22.        }
  23.         for (int i=0;i<numberOfBalls;i++) {
  24.             balls.get(i).erase();
  25.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement