title: Multiple itemlisteners in a single class
body: <p>I am new to Java and Swing and am following <a href="http://zetcode.com/tutorials/javaswingtutorial/basicswingcomponents/" rel="nofollow">zetcode tutorial</a>. I want to add multiple <code>JComboBox</code>es and store the index selected for each one of those. <code>index1</code> should hold selected index from 1st instance of <code>JComboBox</code> and <code>index2</code> should hold selected index from 2nd instance of <code>JComboBox</code>. For one <code>JComboBox</code> it can be done like this:</p>
  
  <pre><code>public ComboBox() {
  
      setLayout(new BoxLayout(getContentPane(), 
      BoxLayout.Y_AXIS));
      add(Box.createRigidArea(new Dimension(0, 35)));
  
      combobox = new JComboBox(authors);
      combobox.addItemListener(this);
      add(combobox);
  }
  public void itemStateChanged(ItemEvent e) {
  
      if (e.getStateChange() == ItemEvent.SELECTED) {
          JComboBox combo = (JComboBox) e.getSource();
          int index = combo.getSelectedIndex();
          display.setIcon(new ImageIcon(
              ClassLoader.getSystemResource(images[index])));
      }
  
  }
  </code></pre>
  
  <p>So if I could write the name of itemlistener that should be called for each <code>JComboBox</code> and then instead of writing <code>combobox.addItemListener(this)</code>, I could write <code>combobox.addItemListener(itemListener1)</code>. How do I do this?</p>