so I'm building a menu for a board game and would like players to be able to set their color with Choosers.
addChoosers(){
JPanel _choosers = new Jpanel();
_choosers.add(new JLabel("Green"));
_green = new Choice();
_green.add("Man");
_green.add("Machine");
_choosers.add(_blue);
_choosers.add(new JLabel("Blue"));
_blue = new Choice();
_blue.add("Man");
_blue.add("Machine");
_choosers.add(_blue);
}
I'd like to build one listener that knows from which chooser it was called and therefore the controller to set up the machine turns in the correct order.
public class PlayerListener implements ItemListener{
@Override
public void itemStateChanged(ItemEvent e) {
)
{//a bunch of else ifs here for each color
if (e.getItem()=="Man")
//do naught
else
//set the appropriate position in turn orientation
}
}
what i'm really asking for here are on which terms to build my if conditions. does e.getItem() return the String of the option, i.e. "Man" or "Machine"? and does e.getSource() return "Green"? Thanks!
PS: I hope this is enough code to make my question understood.