title: Adding a mouse listener to image or image Icon in java
body: <p>How can I to add mouse listener to image or <code>imageIcon</code> in Java?</p>
  <p>Here is my code. I want to do anything with <code>imageIcon</code> after mouse click on it.</p>
  <pre><code>public class Bubbles extends JPanel {
      
      public static final int LINE_OUT = 440;
      int x = 20;
      int y = 50;
      int v = 4;
      
      Image img = new ImageIcon(&quot;res/lop.png&quot;).getImage();
      BackSide back;
      
  
      public Bubbles(int x, int y, int v, BackSide back) {
          this.x = x;
          this.y = y;
          this.v = v;
          this.back = back;
          setFocusable(true);
          
      }
      
   
      public void move() {
          if (y &gt;= 440) {
              y = 0;
          } else {
              y += v;
          }
      }
  
  }
  </code></pre>