title: How do I create an event handler for a JLabel?
body: <p>I want to make it so that if I click on the JLabel, the label becomes a new label with another image attached to it.</p>
  
  <p>So far my code looks like:</p>
  
  <pre><code>public class Picture extends JFrame  {
  
      private ImageIcon _image1;
      private ImageIcon _image2;
      private JLabel _mainLabel;
      private JLabel _mainLabel2;
  
      public Picture(){
          _image1 = new ImageIcon("src/classes/picture1.jpg");
          _image2 = new ImageIcon("src/classes/picture2.jpg");
          _mainLabel = new JLabel(_image1);
          _mainLabel2 = new JLabel(_image2);
  
          add(_mainLabel);
  
          pack();
          setVisible(true);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
  }
  </code></pre>