public class BouncingBall2 extends DBAnimationApplet
1: import java.awt.*;
2:
3: public class BouncingBall2 extends DBAnimationApplet {
4:
5: public BouncingBall2() {
6: super(true); // double buffering
7: }
8:
9: protected void initAnimator() {
10: String att = getParameter("delay");
11: if (att != null)
12: setDelay(Integer.parseInt(att));
13: x = d.width * 2 / 3 ;
14: y = d.height - radius;
15: }
16:
17:
18: protected void paintFrame(Graphics g) {
19: g.setColor(Color.white);
20: g.fillRect(0,0,d.width,d.height);
21: if (x < radius || x > d.width - radius) {
22: dx = -dx;
23: }
24:
25: if (y < radius || y > d.height - radius) {
26: dy = -dy;
27: }
28: x += dx; y += dy;
29: g.setColor(color);
30: g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
31: }
32:
33: protected int x, y;
34: protected int dx = -2, dy = -4;
35: protected int radius = 20;
36: protected Color color = Color.green;
37: }