Java vs C# - AddActionListener vs event subscription
Posted
by
S.O.
on Stack Overflow
See other posts from Stack Overflow
or by S.O.
Published on 2011-03-03T15:08:51Z
Indexed on
2011/03/03
15:24 UTC
Read the original article
Hit count: 161
Very simple question from one somewhat new to Java: when adding an event handler (or whatever it is called in Java) to a Control, MUST it be an object? I mean, in C# I can do
control.event += System.eventHandler(methodThatHandlesEvent)
Sure, that's because we have delegate types in C#, but I was wondering if I can choose which method would be called when an event is raised in Java? I mean, in Java I can have something like
control.AddActionListener(objectWhichClassImplementsActionListener)
And then I have the stupid actionPerformed
method in this class, which is the only method that is called. I know, there are more kinds of listeners, but I can't have a "ActionListenerHandler" class in which I implement several actionPerformed
methods that can be assigned to different controls?
© Stack Overflow or respective owner