-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConThread.java
More file actions
58 lines (49 loc) · 1.42 KB
/
ConThread.java
File metadata and controls
58 lines (49 loc) · 1.42 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
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.*;
import java.net.*;
// This thread deals with the changing images as the charactors walk around the
// screen.
public class ConThread extends Thread
{
private Boolean stopThread = false;
private int curImageIndex = 0;
private int id;
private Image[] images = new Image[2];
private MovableWithDir object;
private int dirrection;
private String character;
ConThread( int dir, String charactor, MovableWithDir obj, int MoveID )
{
object = obj;
dirrection = dir;
}
// This is called inorder to stop the thread
public void endThread()
{
stopThread = true;
}
// This is called when the thread is started. It sets up some variables, and
// then call the function which changes the image every 250 milliseconds
public void run()
{
curImageIndex = 0;
while ( !stopThread )
{
if ( curImageIndex == 1 )
curImageIndex = 2;
else
curImageIndex = 1;
object.changeImage( dirrection, curImageIndex );
pause( 250 );
}
}
private void pause ( int time )
{
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
Logger.getLogger(Movable.class.getName()).log(Level.SEVERE, null, ex);
}
}
}