title: mouse listener not working in card panel
body: <p>i want to add mouselistener to card panel but it is not working....i want to code that when mouse enters card panel ,images change automatically, and they stop moving when mouse exits card panel....three images are added to card panel cp1</p>
  
  <pre><code>public class entry extends JFrame implements MouseListener
  {
  CardLayout clayout1;
  Panel p4,p5,p6,cp1;
  String s2[]={"fourth","fifth","sixth"};
  boolean x;
  
  entry()
  {
  setLayout(null);
      cp1=new Panel();
      clayout1=new CardLayout();
      cp1.setLayout(clayout1);
      cp1.setBounds(0,0,1920,500);
      cp1.addMouseListener(this);  //here iam adding mouselistener to cardpanel
  
      p4=new Panel();
      img4=new ImageIcon("a.jpg");
      l4=new JLabel(img4);
      p4.add(l4);
  
      p5=new Panel();
      img5=new ImageIcon("b.jpg");
      l5=new JLabel(img5);
      p5.add(l5);
  
      p6=new Panel();
      img6=new ImageIcon("3.jpg");
      l6=new JLabel(img6);
      p6.add(l6);
  
      add(cp1);
      cp1.add(p4,"fourth");
      cp1.add(p5,"fifth");
      cp1.add(p6,"sixth");
  }
  public void mouseExited(MouseEvent e)
      { 
           x=true;
  
      }
      public void mouseEntered(MouseEvent e)
      {
          for(int i=0; i&lt;=2;i++){
              clayout1.show(cp1,s2[i]);
              try {
                  Thread.sleep(2000);
              } catch (InterruptedException E) {
  
                  E.printStackTrace();
              }
              if(i==2){
                  i=-1;}
              System.out.println("entered");  //this "entered" is not being printed in console    
              if(x)
              {
              break;  
              }
          }
      }
  </code></pre>