... public void handle(long now) {
28               double elapsedTime = (now - previousTime) / 1000000000.0;
29               previousTime = now;                                      
30               double scale = elapsedTime * velocity;                   
31
32               Bounds bounds = pane.getBoundsInLocal();
33               c.setLayoutX(c.getLayoutX() + dx * scale);
34               c.setLayoutY(c.getLayoutY() + dy * scale);
35
36               if (hitRightOrLeftEdge(bounds)) {
37                  dx *= -1;
38               }
39
40               if (hitTopOrBottom(bounds)) {
41                  dy *= -1;
42               }
43            }
44         }
45
46         timer.start();
47      }
48
49      // determines whether the circle hit left/right of the window
50      private boolean hitRightOrLeftEdge(Bounds bounds) {
51         return (c.getLayoutX() <= (bounds.getMinX() + c.getRadius())) ||
52            (c.getLayoutX() >= (bounds.getMaxX() - c.getRadius()));
53      }
54
55      // determines whether the circle hit top/bottom of the ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.