|
From: Herman v. H. <h_v...@ho...> - 2004-10-13 17:46:12
|
Hi,
I think I can provide you with the answer. the vehicle has to subscribe to
the event. This is done with the addListener(ListenerInterface listener,
EvenType event) method which is in the EventProducer class and thuss in your
crane class. Assuming it is in you r constructor it should look like this:
public class Vehicle implements EventListenerInterface
{
public Vehicle(Crane crane)
{
/** Call super class constructor*/
super();
/** Do all other stuff*/
/** Add our listener*/
try
{
Crane.addListener(this, CONTAINER_RELEASED_EVENT);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/** Methods*/
}
Hope this helps,
regards, Herman van Hovell
>From: "Dirk Samson" <di...@tb...>
>To: <dso...@li...>
>Subject: [Dsol-java] how to listen to fireEvent?
>Date: Wed, 13 Oct 2004 15:10:48 +0200
>
>Dear all,
>
>I've made a "crane" that delivers "containers" every 1..5 timeunits. These
>containers should be picked up by several "someVehicles". I would like to
>have my crane fire an event, CONTAINER_RELEASED_EVENT. The code for this I
>found in the tutorial, section 4.2:
>
>...
>public class QuayCrane extends EventProducer {
> public static final EventType CONTAINER_RELEASED_EVENT = new EventType(
> "CONTAINER_RELEASED_EVENT");
>...
>
>private void releaseContainer () {
>...
>this.fireEvent(CONTAINER_RELEASED_EVENT,
>this.simulator.getSimulatorTime());
>... }
>} // end class
>
>My question:
>
>How do I get an instance of my someVehicle to listen to this event? The
>events in the tutorial are (so it seems) only used by the Tallies. For this
>moment I;m not interested in the prioritization of my someVehicles; I just
>want them to respond.
>
>Is this the proper mechanism to create interaction between objects in the
>simulation??
>
>Dirk Samson
>(PS My very-first-test-project can be found on the CVS Server: "SPM9322 -
>port")
>
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
>Use IT products in your business? Tell us what you think of them. Give us
>Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
>http://productguide.itmanagersjournal.com/guidepromo.tmpl
>_______________________________________________
>Dsol-java mailing list
>Dso...@li...
>https://lists.sourceforge.net/lists/listinfo/dsol-java
_________________________________________________________________
MSN Search, for accurate results! http://search.msn.nl
|