jeudi 7 juillet 2016

Unable to select item from combobox

I've implemented ActionListener so that my ship list changes according to the nation and ship type, but the problem is that I can't select any ships.

Any idea(s) on where I may have went wrong?

private class ShipNameListener implements ActionListener
{   
    public ShipNameListener()
    {
        view.setShipNameListener(this);
    }   

    @Override
    public void actionPerformed(ActionEvent arg0) 
    {           
        if (view.getNationComboBox().getSelectedItem() == "USA")
        {
            if (view.getShipTypeComboBox().getSelectedItem() == "Battleship")
            {
                view.setShipList(lists.getUSABattleships());
            }
            else if (view.getShipTypeComboBox().getSelectedItem() == "CV")
            {
                view.setShipList(lists.getUSACVs());
            }
            else if (view.getShipTypeComboBox().getSelectedItem() == "Destroyer")
            {
                view.setShipList(lists.getUSADestroyers());
            }
            else if (view.getShipTypeComboBox().getSelectedItem() == "Cruiser")
            {
                view.setShipList(lists.getUSACruisers());
            }
        }           
    }       
}

Above is said ActionListener in Controller class.

public void setShipNameListener(ActionListener al) 
{
    comboBoxNation.addActionListener(al);
    comboBoxShipType.addActionListener(al);
    comboBoxShipName.addActionListener(al);     
}

Above is setter in View class.

Can't select other items from combobox

Aucun commentaire:

Enregistrer un commentaire