I'm doing an application in java with JList and a Textarea. I want the textarea to update as the JList changes. I'm uncertain about how to correctly implement the action listeners.
I want the listeners to be in there own classes. So i've set that up. The problem is that the listeners "knows" about one of the other classes that i feel it shouldn't know about.
public class ll implements ListSelectionListener {
cpp updatecpp;
public ListListener(cpp instanceOfCpp)
{
updatecpp = instanceOfCpp;
}
@Override
public void valueChanged(ListSelectionEvent e) {
if(!e.getValueIsAdjusting())
{
JList jlist = (JList)e.getSource();
String updatevalue = jlist.getSelectedValue().toString();
updatecpp.updateChat(updatevalue);
}
}
}
As you can see the constructor takes an instance of cpp and then updates the textArea by calling the method updateChat. Can this be done, still having the listeners in its own class but without having to get a instance of cpp?