Reputation: 530
I'm trying to write a program in which I have to create custom events. I have seen some examples like Mr.Happy Object. My problem is that I'm not allowed to fire events myself and they have to be fired when a particular event has happened. Like a program that would print 80 if only data has come from the 80 port.
I really don't know how it could be possible. What is the thing that I have to use?
Upvotes: 3
Views: 58
Reputation: 270995
There is no intrinsic difference between "firing an event yourself" and "firing an event when something happens". In the context of custom events, you all do it by you yourself writing code that fires your event. No one can fire your custom events for you.
Basically, you gotta write something like this somewhere in your code:
for (MyEventListener listener : listeners) {
listener.onMyEvent(...);
}
If you are listening for data coming in from a port. Good! Look up how to do that and you get the data, call all the event listeners like I did above. This is a stating point I found.
Upvotes: 1