|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
infpp.oceanlife.OceanObject
public abstract class OceanObject
An abstract class implementing the common properties of the different types of ocean object. In particular, an abstract constructor is used.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected static int |
COLLISION_LEFT_BOUND
Used to signal that the object has collided with the ocean's left bound. |
protected static int |
COLLISION_LOWER_BOUND
Used to signal that the object has collided with the ocean's lower bound. |
protected static int |
COLLISION_RIGHT_BOUND
Used to signal that the object has collided with the ocean's right bound. |
protected static int |
COLLISION_UPPER_BOUND
Used to signal that the object has collided with the ocean's upper bound. |
protected Ocean |
currentOcean
The currently-used ocean. |
protected int[] |
direction
The object's direction vector. |
(package private) static int |
id
For unique ocean object id's. |
private boolean |
isHighlighted
A flag to indicate whether the object is currently highlighted. |
protected int |
myID
ID for each ocean object. |
protected static int |
NO_COLLISION
Used to indicate that no collision has occurred. |
private javax.swing.ImageIcon |
objectIcon
ID for each ocean object. |
private int[] |
position
The object's position vector. |
private boolean |
toDie
A flag indicating whether the object's thread should die. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
protected |
OceanObject(int x,
int y,
javax.swing.ImageIcon objectIcon,
Ocean currentOcean)
|
Method Summary | |
---|---|
java.awt.Dimension |
getDimensionsOfIcon()
|
javax.swing.ImageIcon |
getObjectIcon()
|
int |
getObjectID()
|
java.lang.String |
getObjectIDString()
|
int[] |
getPosition()
|
int |
getPositionX()
|
int |
getPositionY()
|
static int |
getUniqueOceanObjectID()
|
boolean |
isHighlighted()
|
boolean |
isToDie()
|
protected int |
objectCollidesWithOceanBounds()
|
void |
run()
|
void |
setHighlighted(boolean isHighlighted)
|
void |
setObjectIcon(javax.swing.ImageIcon objectIcon)
|
void |
setPositionWhenAdding(int[] position)
|
void |
setPositionWhenMoving(int[] newPosition)
This method is responsible for setting the position of objects already in the ocean. |
void |
setToDie(boolean toDie)
|
java.lang.String |
toString()
|
protected void |
updateDirection()
|
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static int id
protected int myID
private javax.swing.ImageIcon objectIcon
private boolean isHighlighted
protected Ocean currentOcean
private boolean toDie
protected static final int NO_COLLISION
protected static final int COLLISION_UPPER_BOUND
protected static final int COLLISION_LOWER_BOUND
protected static final int COLLISION_LEFT_BOUND
protected static final int COLLISION_RIGHT_BOUND
private int[] position
protected int[] direction
Constructor Detail |
---|
protected OceanObject(int x, int y, javax.swing.ImageIcon objectIcon, Ocean currentOcean) throws java.lang.Exception
x
- The x-coordinate of the ocean object.y
- The y-coordinate of the ocean object.objectIcon
- Icons for the ocean objects.currentOcean
- The current used ocean.
java.lang.Exception
- Throws exception for the position.Method Detail |
---|
public javax.swing.ImageIcon getObjectIcon()
public void setObjectIcon(javax.swing.ImageIcon objectIcon)
objectIcon
- the objectIcon to setprotected void updateDirection()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public static int getUniqueOceanObjectID()
public int getObjectID()
public java.lang.String getObjectIDString()
public boolean isHighlighted()
public void setHighlighted(boolean isHighlighted)
isHighlighted
- whether or not the object should be highlighted.public int[] getPosition()
public int getPositionX()
public int getPositionY()
public void setPositionWhenAdding(int[] position) throws java.lang.Exception
position
- the position to set
java.lang.Exception
protected int objectCollidesWithOceanBounds()
public void setPositionWhenMoving(int[] newPosition) throws java.lang.Exception
newPosition
- the object's new position
java.lang.Exception
- if the object is about to swim out of the oceanpublic boolean isToDie()
public void setToDie(boolean toDie)
toDie
- a boolean indicating whether the object's thread should die.public java.lang.String toString()
toString
in class java.lang.Thread
public java.awt.Dimension getDimensionsOfIcon()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |