Java vs C# - AddActionListener vs event subscription
- by S.O.
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?