0

I have a combobox with language menus on a Jframe , on selection of chinese from combo I have to call another action listener class ChineseButnListener. How can I correct this code?`

 ActionListener actionListener = new ActionListener() {
                 public void actionPerformed(ActionEvent actionEvent) {
                   ItemSelectable language = (ItemSelectable)actionEvent.getSource();
                   System.out.println(selectedString(language));

                   if(selectedString(language).equals("Chinese")){
                 // addActionListener(new ChineseButnListener());
                   }else
                    //addActionListener(new EnglishButnListener());
                 }
               };

    class ChineseButnListener implements ActionListener {
            public void actionPerformed(ActionEvent evt) {
            //
            }
        }

`
Agnosco
  • 155
  • 2
  • 11
  • 1
    I would suggest you to keep one action listener and manage you logic inside it. – Darshan Lila Dec 01 '14 at 06:11
  • 1
    `selectedString(language) == "Chinese"` is not how `String` comparision works in Java, use `"Chinese".equals(selectedString(language))` or similar...Assuming that `ChineseButnListener` is attached to a button of some kind, you can call the button's `doClick` method to automatically trigger the button's registered `ActionListener`s – MadProgrammer Dec 01 '14 at 06:12

0 Answers0