| Total Complexity | 6 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | package example.swing; |
||
| 8 | public class Ball { |
||
| 9 | private Ellipse ball; |
||
|
|
|||
| 10 | private double dx, dy; |
||
| 11 | |||
| 12 | public Ball(DrawingPanel panel) { |
||
| 13 | double heading = Math.random() * Math.PI * 2; |
||
| 14 | dx = Math.cos(heading); |
||
| 15 | dy = Math.sin(heading); |
||
| 16 | |||
| 17 | ball = new Ellipse( |
||
| 18 | Math.random() * panel.getWidth(), |
||
| 19 | Math.random() * panel.getHeight(), |
||
| 20 | 20, 20, |
||
| 21 | panel |
||
| 22 | ); |
||
| 23 | ball.setFillColor(new Color((float) Math.random(), (float) Math.random(), (float) Math.random())); |
||
| 24 | ball.setStrokeColor(ball.getFillColor()); |
||
| 25 | } |
||
| 26 | |||
| 27 | public void move() { |
||
| 28 | ball.translate(dx, dy); |
||
| 29 | if (ball.getX() < 0 || ball.getX() + ball.getWidth() > ball.getDrawingPanel().getWidth()) { |
||
| 30 | dx = -dx; |
||
| 31 | } |
||
| 32 | if (ball.getY() < 0 || ball.getY() + ball.getWidth() > ball.getDrawingPanel().getHeight()) { |
||
| 33 | dy = -dy; |
||
| 34 | } |
||
| 37 |