|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.gameEngine.game.GameRelatedObject
public abstract class GameRelatedObject
Class GameRelatedObject
is the superclass for all objects used
in a game. This class sets up an event framework that allows events to be
fired by an object and their listeners to be automatically updated.
Constructor Summary | |
---|---|
protected |
GameRelatedObject()
Creates and initializes a GameRelatedObject . |
Method Summary | |
---|---|
void |
addEventListener(java.util.EventListener listener)
Adds an EventListener to the GameRelatedObject . |
void |
clearListeners()
Clears the listeners that are listening to this GameRelatedObject . |
boolean |
equals(java.lang.Object o)
|
void |
fire(java.util.EventObject event)
Calls the all methods of every registered listener that takes the given event's type as the parameter. |
void |
fire(java.util.EventObject event,
java.util.EventListener listener)
Fires an event to a specific listener. |
void |
fire(java.util.EventObject event,
java.lang.String methodName)
Determines if any registered listeners have a method matching the given methodName and event's type as the parameter; if so it invokes the method on each of the listeners. |
java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.Set<java.util.EventListener>> |
getEventListeners()
Method for getting all of the listeners associated with this object. |
int |
getID()
Returns this GameRelatedObject 's ID, which was derived from
the system timer at the time of its instantiation. |
int |
getListenerCount()
Returns the number of listeners registered on this
GameRelatedObject
. |
void |
removeEventListener(java.util.EventListener listener)
Removes an EventListener from the GameItem . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected GameRelatedObject()
GameRelatedObject
.
Method Detail |
---|
public final int getID()
GameRelatedObject
's ID, which was derived from
the system timer at the time of its instantiation. This
Integer
is expected to be unique for each instance of
GameRelatedObject
Integer
representation of this object's unique IDpublic int getListenerCount()
GameRelatedObject
. Intended to be similar in usage to
Observable.countObservers()
.
int
number of listenerspublic final void addEventListener(java.util.EventListener listener)
EventListener
to the GameRelatedObject
.
listener
- to be addedpublic final void removeEventListener(java.util.EventListener listener)
EventListener
from the GameItem
. If
the GameRelatedObject
is not being listened to by the
EventListener
then nothing will occur. The actual removing
will only occur when the set of listeners is not in use.
listener
- to be removedpublic final void clearListeners()
GameRelatedObject
.
public final java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.Set<java.util.EventListener>> getEventListeners()
Map
of EventListener
s that are organized
in bins according to their classpublic final void fire(java.util.EventObject event)
Calls the all methods of every registered listener that takes the given
event's type as the parameter. If a listener is a GameItem
,
then it's relevant method is only called if GameItem#isEnabled()
is true.
Convenience method for calling fire(event, null)
.
event
- to be firedpublic final void fire(java.util.EventObject event, java.lang.String methodName)
GameItem
, then it's relevant
method is only called if GameItem#isEnabled()
is true.
For example: If the event is a TimeEvent
, a
TimeListener
is registered for this
GameRelatedObject
, and "timeChanged" is the
methodName, then the
TimeListener.timeUpdated(TimeUpdateEvent)
method will be invoked
with event as the parameter.
event
- to be firedmethodName
- to be invokedpublic final void fire(java.util.EventObject event, java.util.EventListener listener)
event
- to firelistener
- to fire the event topublic final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |