title: Adding a MouseListener or MouseMotionListener to my JLabel that is inside of a Jpanel in my checkers-like board
body: <p>I'm really not sure what to do. I had started by making a new class that implements both MouseMotionListener and MouseListener and that takes in its constructor the JLabel:</p>
  
  <pre><code>import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import java.awt.event.MouseMotionListener;
  import javax.swing.JLabel;
  
  public class motion implements MouseMotionListener, MouseListener {
  
      motion(JLabel im) {
          label1 = im;
      }
  
      @Override
      public void mousePressed(MouseEvent e) {
          if (e.getSource() == label1) {
              drag = true;
          } 
      } 
  
      @Override
      public void mouseReleased(MouseEvent e) {
          drag = false;
      }
  
      @Override
      public void mouseDragged(MouseEvent e) {
          if (drag == true) {
              mouseX = e.getX();
              mouseY = e.getY();
              label1.setBounds(mouseX, mouseY, 
                      label1.getWidth(), label1.getHeight());
          }
      }
  
      public void mouseMoved(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void mouseClicked(MouseEvent e) {}  
      private JLabel label1;
      private int mouseX;
      private int mouseY;
      private boolean drag = false;
  
  }
  </code></pre>
  
  <p>This is the code for my board. Currently the pieces aren't able to move. I had a line in each if statement to add a MouseMotionListener--picLabel.addMouseMotionListener(new motion(picLabel))--but that didn't work.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import java.awt.event.MouseMotionListener;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  
  import javax.imageio.ImageIO;
  import javax.swing.*;
  
     public class Checkerboard {
         public static void main (String args[]) throws IOException {
           JFrame checkerBoard = new JFrame();
           checkerBoard.setSize(700,700);
           checkerBoard.setTitle("Lines of Action");
           checkerBoard.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           int row = 8;
           int col = 8;
           Container pane = checkerBoard.getContentPane();
           pane.setLayout(new GridLayout(row,col));
           Color checker;   
           for (int x = 1; x &lt;= (row * col); x++) {
              int altr = 0;
              altr = (x-1) % col;
              altr += (x-1) / col;
  
              if (altr % 2 == 0) {
                 checker = Color.darkGray;
              } else {
                 checker = Color.lightGray;
              }
  
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(400/row, 400/col));
              panel.setBackground(checker);
              if ((x &lt; 8 &amp;&amp; x &gt; 1) || (x &lt; 64 &amp;&amp; x &gt; 57)) {
                  BufferedImage myPicture = 
              ImageIO.read(new  File("C:\\Users\\srjames90\\Downloads\\BlackPiece.png"));
                  JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
                  picLabel.addMouseMotionListener(new motion(picLabel));
                  panel.add(picLabel);
              } else if(check(x)) {
                  BufferedImage myPicture = 
              ImageIO.read(new File("C:\\Users\\srjames90\\Downloads\\WhitePiece.png"));
                  JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
                  panel.add(picLabel);
              }
              pane.add(panel);
           }
           checkerBoard.setVisible(true);
        }
  
        static boolean check(int y) {
             return y == 9 || y == 16 || y == 17 || y == 24 || y == 25
                     || y == 32 || y == 33 || y == 40 || y == 41 || y == 48
                         || y == 49 || y == 56;
         }
     }
  </code></pre>