[java] Events

Started by
3 comments, last by koatto 23 years, 3 months ago
Events can be fired by any object or only gui components can generate them? Can i make an object trigger a custom event?
Advertisement
Any object can deliver events, through the dispatchEvent(AWTEvent e) method in the Component class. Simply call that method with an appropriate event, on the GUI component you would like to have receive the event.

As far as custom events go, it''s possible, through careful study of the AWTEvent class and the EventListener interface... I haven''t done it though, so all I can tell you is that it''s possible.
"Events can be fired by any object"

In reality this is the case, as event methods, such as
actionPerformed(actionEvent event) are public methods.

So there is nothing to stop you creating your own actionEvent (or mouseEvent, or windowEvent or whatever) and passing it into that method to trigger your own "custom" event.

Now, one could discuss whether or not this is good coding practice.. but it can be useful to get you out of a pinch

Mark



----
www.emanatemultimedia.com
----
<< ...and here is one we developed earlier... >>
What the EventListener interface really do?
The api docs are very short of infos about...

EventListener does nothing. It''s a tagging interface like Serializable and Remote.

buh!

This topic is closed to new replies.

Advertisement