Java JComboBox上的侦听器未拾取所选内容

Java JComboBox上的侦听器未拾取所选内容,java,jframe,listener,jcombobox,Java,Jframe,Listener,Jcombobox,我用一个JButton测试了监听器,它成功了,但我不明白为什么它不能用组合框实现我想要的功能。我希望它根据用户从组合框中选择的内容执行不同的操作。e、 g.当用户选择USA时,预期的行为是关闭GUI窗口 public class AccountListTest extends JFrame implements ActionListener{ public JComboBox combo; AccountListTest() { JFrame myfr

我用一个
JButton
测试了
监听器
,它成功了,但我不明白为什么它不能用组合框实现我想要的功能。我希望它根据用户从组合框中选择的内容执行不同的操作。e、 g.当用户选择
USA
时,预期的行为是关闭GUI窗口

public class AccountListTest extends JFrame implements ActionListener{

    public JComboBox combo;

    AccountListTest()
    {
        JFrame myframe = new JFrame();
        myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel mypanel = new JPanel();

        String [] country = {"USA","Ireland"};


        //JComboBox combo = new JComboBox();
        myframe.setSize(450,300);

        combo = new JComboBox(country);
        combo.addActionListener(this);

        mypanel.add(combo , BorderLayout.PAGE_END);

        myframe.add(mypanel);


        myframe.setVisible(true);
        AddressFactory afactory = new AddressFactory();

        //afactory.getAccountList(USA).display();
        //afactory.getAccountList(Ireland).display();

        combo.addActionListener(this);

        myframe.add(mypanel);
        myframe.setVisible(true);


    }


    public  static void main (String[] args)
    {
        new AccountListTest();

    }

    public void actionPerformed(ActionEvent e) {
        Object originator = e.getSource();

        if(e.getActionCommand().equals("USA"))
        {
            System.exit(0);
        }
        else if(e.getActionCommand().equals("Ireland"))
        {
            System.out.println("IRL SEL");
        }
        // TODO Auto-generated method stub

    }
}

当触发
actionPerformed
时,尝试获取组合的字符串:

public void actionPerformed(ActionEvent e) {
        String selectedValue = combo.getSelectedValue().toString();
        if("USA".equalsIgnoreCase(selectedValue))
        {
            //Do Something for USA
        }
        else if("Ireland".equalsIgnoreCase(selectedValue))
        {
            //Do something irish
        }
        // TODO Auto-generated method stub

    }

可能复制完美的作品非常感谢