- Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmyApplet.java
55 lines (48 loc) · 1.42 KB
/
myApplet.java
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
importjava.applet.Applet;
importjava.awt.Color;
importjava.awt.Graphics;
classBall {
intx, y, radius, dx, dy;
ColorBallColor;
publicBall(intx, inty, intradius, intdx, intdy, ColorbColor) {
this.x = x;
this.y = y;
this.radius = radius;
this.dx = dx;
this.dy = dy;
BallColor = bColor;
}
}
publicclassmyAppletextendsAppletimplementsRunnable {
BallredBall;
publicvoidinit() {
redBall = newBall(150, 0, 20, 2, 5, Color.red);
Threadt = newThread(this);
t.start();
}
publicvoidpaint(Graphicsg) {
g.setColor(redBall.BallColor);
g.fillOval(redBall.x, redBall.y, redBall.radius, redBall.radius);
}
publicvoidrun() {
try {
Colorc = redBall.BallColor;
redBall.BallColor = newColor(c.getRed(), c.getBlue() + 20, c.getGreen());
redBall.y = redBall.y + redBall.dy;
} catch (Exceptione) {
}
while (redBall.BallColor.getBlue() != 255) {
try {
displacementOperation(redBall);
Thread.sleep(1000);
repaint();
} catch (Exceptione) {
}
}
}
publicvoiddisplacementOperation(Ballball) {
Colorc = ball.BallColor;
ball.BallColor = newColor(c.getRed(), c.getBlue() + 20, c.getGreen());
ball.y = ball.y + ball.dy;
}
}