I have a presenter class and several text fields in my view.
I want my presenter to say “every textfields that are listening to me, please do something now”.
BUT I don’t want to use Observabe/Observer, since I already use it and I don’t want to get confused.
To be a bit more specific, I want the textfields to update a Map in the presenter :
Presenter.java :
public class Presenter {
private HashMap<String,MyObject> map;
theMethod(){
//to all text fields, please update the map
Then a textfield in a panel :
JTextField tf = new JTextField("tf 1");
tf.//add something to listen to the presenter
The beginning of the process is the method in the presenter :
- theMethod() is called (not by the view)
- theMethod() triggers a method linked to the TextFields
- Every methods called in every TextFields are doing something
I found it !
I use a Runnable callback in the presenter.
In my view I have :
And in my presenter :
Of course, I’m going to implement some List for each textfield.
In the end, I have the expected behavior :
in the presenter
when he wants to !
Great !