Hello I have ItemChangeListener... but I want this to be responsible for more than one view. ( If this is not the right way to do this please tell me how else ) So that when I choose an item in a JComboBox I get to work with that object I selected
public class ItemChangeListener implements ItemListener {
Persoon selectedPerson;
PersoonView view;
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
Object item = event.getItem();
// do something with object
if(item instanceof Persoon) {
this.selectedPerson = (Persoon) item;
view.setOverzicht(this.selectedPerson);
} else {
this.selectedPerson = null;
}
}
}
}
But as u can see right now.. It only works with one specific view the PersoonView view class. How should I modify this to work with more than one view?
edit: In my view I do this ( right now I have 2 view )
personenList = new JComboBox();
for (Persoon p : app.getPersonen()) {
personenList.addItem(p.getNaam());
}
personenList.addItemListener(new ItemChangeListener());
Everytime I select another item I want to get the selectedPerson to work with in that view for example I want to do this in my ActionListener that is in my view.
selectedPerson.voegtoeRek(new Rekening(Integer.parseInt(nieuwnr.getText()), selectedPerson));
So practically I need to find some way to get that variabel out of ItemChangeListener.