title: JComboBox will display first item in array, but throws an Exception when selecting second item
body: <p>I can switch order of filenames "dr.png" or "MF4040.png" and it will default as it is supposed to do, code compiles, runs and ALWAYS works while displaying the first item in the array, but will throw an exception when the second item is selected in the <code>JComboBox</code> when the program is running. Also I am using JDK1.6 and Eclipse 4.2. Source is from Bucky's JAVA tutorial <a href="https://www.youtube.com/watch?v=XS4-5GmRnp8&amp;index=69&amp;list=PL484D73FA74A11AC9" rel="nofollow">https://www.youtube.com/watch?v=XS4-5GmRnp8&amp;index=69&amp;list=PL484D73FA74A11AC9</a></p>
  
  <p>Here is the code... </p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class gui extends JFrame{
  
  private JComboBox box;
  private JLabel picture;
  
  private static String[] filename = {"dr.png", "MF4040.png" };
  private Icon[] pics = {new ImageIcon(getClass().getResource(filename[0]))};
  
  public gui(){
      super("The title");
      setLayout(new FlowLayout());
  
      box = new JComboBox(filename);
  
      box.addItemListener(
          new ItemListener(){             
              public void itemStateChanged(ItemEvent event){
                  if(event.getStateChange()==ItemEvent.SELECTED)
                      picture.setIcon(pics[box.getSelectedIndex()]);
  
               }
           }      
  );
  
      add(box);
      picture=new JLabel(pics[0]);
  
       add(picture);
  
  }
  }   
  </code></pre>
  
  <p>AND MY MAIN...</p>
  
  <pre><code> import javax.swing.JFrame;
  
   public class apples {
  
  
  public static void main(String[] args) {
  
      gui go = new gui();
      go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      go.setSize(300,200);
      go.setVisible(true);
    }
  }
  </code></pre>
  
  <p>Here are the exceptions that get thrown:</p>
  
  <pre class="lang-none prettyprint-override"><code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
       at gui$1.itemStateChanged(gui.java:24)
       at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1205)
       at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1262)
       at javax.swing.JComboBox.contentsChanged(JComboBox.java:1309)
       at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:100)
       at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:88)
       at javax.swing.JComboBox.setSelectedItem(JComboBox.java:557)
       at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:603)
       at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:831)
       at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
       at java.awt.Component.processMouseEvent(Component.java:6414)
       at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
       at com.apple.laf.AquaComboBoxPopup$1.processMouseEvent(AquaComboBoxPopup.java:132)
       at java.awt.Component.processEvent(Component.java:6179)
       at java.awt.Container.processEvent(Container.java:2084)
       at java.awt.Component.dispatchEventImpl(Component.java:4776)
       at java.awt.Container.dispatchEventImpl(Container.java:2142)
       at java.awt.Component.dispatchEvent(Component.java:4604)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4618)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4279)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4209)
       at java.awt.Container.dispatchEventImpl(Container.java:2128)
       at java.awt.Window.dispatchEventImpl(Window.java:2492)
       at java.awt.Component.dispatchEvent(Component.java:4604)
       at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:717)
       at java.awt.EventQueue.access$400(EventQueue.java:82)
       at java.awt.EventQueue$2.run(EventQueue.java:676)
       at java.awt.EventQueue$2.run(EventQueue.java:674)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
       at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:97)
       at java.awt.EventQueue$3.run(EventQueue.java:690)
       at java.awt.EventQueue$3.run(EventQueue.java:688)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:687)
       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
  </code></pre>