Java Reference
In-Depth Information
protected
protected volatile
false
;
/** The time in mSec to pause between each move. */
protected
volatile
boolean
boolean
done
=
false
protected volatile
int
sleepTime
=
250
;
/** The direction for this particular sprite. */
protected
volatile
int
protected
int
int
direction
;
/** The direction for going across the page */
public
public static
int
HORIZONTAL
=
1
;
/** The direction for going up and down */
public
static final
final
int
public static
int
VERTICAL
=
2
;
/** The direction for moving diagonally */
public
static final
final
int
public static
static final
final
int
int
DIAGONAL
=
3
;
/** Construct a Sprite with a Component parent, image and direction.
* Construct and start a Thread to drive this Sprite.
*/
public
public
Sprite
(
Component parent
,
Image img
,
int
int
dir
) {
this
this
.
parent
=
parent
;
this
this
.
img
=
img
;
switch
switch
(
dir
) {
case
case
VERTICAL:
case
case
HORIZONTAL:
case
case
DIAGONAL:
direction
=
dir
;
break
break
;
default
default
:
throw
throw new
new
IllegalArgumentException
(
"Direction "
+
dir
+
" invalid"
);
}
setSize
(
img
.
getWidth
(
this
this
),
img
.
getHeight
(
this
this
));
}
/** Construct a sprite with the default direction */
public
public
Sprite
(
Component parent
,
Image img
) {
this
this
(
parent
,
img
,
DIAGONAL
);
}
/** Start this Sprite's thread. */
public
public
void
void
start
() {
t
=
new
this
);
t
.
setName
(
"Sprite #"
+ ++
spriteNumber
);
t
.
start
();
new
Thread
(
this
}
/** Stop this Sprite's thread. */
public
public
void
void
stop
() {
iif
(
t
==
null
null
)
return
return
;
System
.
out
.
println
(
"Stopping "
+
t
.
getName
());