【发布时间】:2016-06-26 23:03:34
【问题描述】:
我已经实现了ActionListener,这样我的舰船列表就会根据国家和舰船类型而变化,但问题是我无法选择任何舰船。
关于我可能出错的地方有什么想法吗?
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());
}
}
}
}
以上是Controller类中的ActionListener。
public void setShipNameListener(ActionListener al)
{
comboBoxNation.addActionListener(al);
comboBoxShipType.addActionListener(al);
comboBoxShipName.addActionListener(al);
}
以上是View类中的setter。
【问题讨论】: