-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpDownBall.java
More file actions
67 lines (50 loc) · 1.62 KB
/
Copy pathUpDownBall.java
File metadata and controls
67 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
/**
The UpDownBall class is responsible for managing the life of one
ball that moves up the screen, then down, and stopping when it
reaches the bottom of the window.
*/
class UpDownBall extends Thread {
// ball size
public static final int SIZE = 50;
// delay time between frames of animation (ms)
public static final int DELAY_TIME = 33;
// pixels to move each frame
public static final int Y_SPEED = 4;
// latest location of the ball
private Point upperLeft;
// how far to fall?
private int bottom;
// who do we live in so we can repaint?
private JComponent container;
/**
Construct a new UpDownBall object.
@param startCenter the initial point at which the center of the
ball should be drawn
@param container the Swing component in which this ball is being
drawn to allow it to call that component's repaint method
*/
public UpDownBall(Point startCenter, JComponent container) {
upperLeft = new Point(startCenter.x - SIZE/2, startCenter.y - SIZE/2);
this.bottom = container.getHeight();
this.container = container;
}
/**
Draw the ball at its current location.
@param g the Graphics object on which the ball should be drawn
*/
public void paint(Graphics g) {
g.fillOval(upperLeft.x, upperLeft.y, SIZE, SIZE);
}
/**
This object's run method, which manages the life of the ball as it
moves up and then down the screen.
*/
@Override
public void run() {
}
}