title: GUI That displays each image of an Array one at a time
body: <p>I am extremely new to GUI's (and Java, started less than 3 months ago) and need some help with a GUI I am doing for a homework assignment. I have come here as a last resort as I cannot figure this out and have been working on it for hours.</p>
  
  <p>I need to make a GUI that will go through and Array of ImageIcons and will display each ImageIcon one at a time (erasing the previous one displayed). I have gotten it to where it displays my first image, but then my JButton does absolutely nothing and I have no clue how to get the thing to work. I have looked through my textbook and numerous online sources and examples my teacher has given and still nothing. I know once I see a solution I'll feel stupid but right now, I'm tired and am starting to not think straight because I have been doing this for so long. PLEASE HELP =D!!!</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.ImageIcon;
  
  public class HangmanPanel extends JPanel {
      private JLabel imageLabel;
      private ImageIcon[] images;
      private JButton nextImage;
      private int imageNumber;
  
  
      public HangmanPanel() {
  
          nextImage = new JButton("Next Image");
          nextImage.setEnabled(true);
          nextImage.setToolTipText("Press for next image.");
          nextImage.addActionListener(new ButtonListener());
  
          images = new ImageIcon[8];
          // Populating the array
          {
              images[0] = new ImageIcon("hangman0.png");
              images[1] = new ImageIcon("hangman1.png");
              images[2] = new ImageIcon("hangman2.png");
              images[3] = new ImageIcon("hangman3.png");
              images[4] = new ImageIcon("hangman4.png");
              images[5] = new ImageIcon("hangman5.png");
              images[6] = new ImageIcon("hangman6.png");
              images[7] = new ImageIcon("hangman7.png");
          }
  
          setBackground(Color.white);
  
          add(nextImage);
          int count = 0;
          while (images.length &gt; count)
          imageLabel = new JLabel (images[imageNumber]);
          count++;
          imageNumber++;
          add (imageLabel);
      }
  
  
      public void paint(Graphics page) {
          super.paint(page);
  
  
      }
      private class ButtonListener implements ActionListener{
          public void actionPerformed(ActionEvent event) {
              imageNumber++;
              }
  
          }
      }
  </code></pre>