+ 2
Access from class B to A with Listener
https://code.sololearn.com/c6AicfkMc7v2/?ref=app If a class like B in the example Code has implemented a Listener(e.g. MouseListener) and in class A is an Instance from B, how can I call a Method from A with the implementation of the Method in class B. The example Code makes it clearer what I mean. I have read about a callback function to do this. Are there more ways to do this or is that a general design failure from me?
3 Antworten
0
Why dont you just make void hello static and call A.hello() in the aListener method
+ 1
Do you want to change the implementation in B based on the listener?
+ 1
Lord HN cool idea but nope 😆
Let us say that the Listener is a MouseListener and the overriden method is mouseClicked or something similar.
Now the Listener triggers and the method mouseClicked is called.
And this method calls the method from A.
I hope it's now more clear. 😅