-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingPic.java
More file actions
120 lines (93 loc) · 1.92 KB
/
Copy pathMovingPic.java
File metadata and controls
120 lines (93 loc) · 1.92 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import java.awt.*;
public class MovingPic extends Thread
{
private int delay;
private int x;
private int y;
private int xChange, yChange;
private Image pic;
private boolean alive;
private boolean leftToRight = true;
public void setAlive(boolean inAlive)
{
alive = inAlive;
}
public void setX(int inX)
{
x = inX;
}
public void setY(int inY)
{
y = inY;
}
public void setXChange(int inXc)
{
xChange = inXc;
}
public void setYChange(int inYc)
{
yChange = inYc;
}
public Image getImage()
{
return pic;
}
public boolean getAlive()
{
return alive;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public int getXChange()
{
return xChange;
}
public int getYChange()
{
return yChange;
}
public int getDelay()
{
return delay;
}
public void setDelay(int inDelay)
{
if (inDelay > 0)
delay = inDelay;
else
delay = 20;
}
public MovingPic(Image inPic, int inDelay, int inX, int inY, int inXc, int inYc)
{
//setDelay(inDelay);
delay = 150;
x = inX;
y = inY;
//yChange = inYc;
//xChange = inXc;
xChange = 20;
pic = inPic;
alive = false;
}
public void run()
{
while(alive)
{
int newX = leftToRight ? x + xChange : x - xChange;
if (newX > 1150)
leftToRight = false;
else if (newX < 0)
leftToRight = true;
x = newX;
try {
sleep(delay);
} catch(Exception e){}
}
}
}