Guest User

Untitled

a guest
Apr 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.awt.*;
  2. import java.util.*;
  3. public class CopyOfPongette {
  4.  
  5. public static void main(String[] args) {
  6. Random r = new Random();
  7. int width = 150;
  8. int height = 237;
  9. DrawingPanel2 panel = new DrawingPanel2(width, height);
  10. Graphics g = panel.getGraphics();
  11. panel.setBackground(Color.red);
  12.  
  13. int nMoves = 2000;
  14. int dx = 2;
  15. int dy = 1;
  16.  
  17. Circle c1 = new Circle(40, 40, 25);
  18.  
  19. for ( int i = 0; i < nMoves; i++)
  20. {
  21. c1.draw(g);
  22. panel.sleep(25); // pause
  23. c1.erase(g, Color.white);
  24.  
  25. if (c1.hitsVerticalWall(width))
  26. dx = -dx;
  27. c1.move(dx, dy);
  28. g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
  29.  
  30. if (c1.hitsHorizontalWall(height))
  31. dy = -dy;
  32. c1.move(dx, dy);
  33. g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
  34.  
  35. }
  36. c1.draw(g);
  37. }
  38. }
Add Comment
Please, Sign In to add comment