title: Java (JFrames): mouseListener() gets called only on the last 2 elements of the ArrayList
body: <p>I am trying to make a simple checkers game, but when I run the current version that prints 10 squares of a random color (white or black) the mouseListener of the Block class only responds to the last 2 blocks and not to any other blocks.  I have absolutely no idea why this would only work for 2 blocks.  The code for the JFrame is in MyCraft.java, the code for the actual panel that is on the frame is in MyCraftPanel, and the code for the Block instances are in Block.java</p>
  
  <p>If anyone could respond their feedback would be much appreciated!</p>
  
  <p>Code for MyCraft.java: </p>
  
  <pre><code>package com.matthewpipie.MyCraft;
  
  import javax.swing.JFrame;
  
  public class MyCraft {
  
      public static void main(String[] args) {
          final int FRAME_WIDTH = 1280;
          final int FRAME_HEIGHT = 720;
  
          JFrame frame = new JFrame("MyCraft");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(new MyCraftPanel());
          frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
          frame.setVisible(true);
      }
  
  }
  </code></pre>
  
  <p>Code for MyCraftPanel.java: <a href="http://pastebin.com/9bQDh2Hm" rel="nofollow">http://pastebin.com/9bQDh2Hm</a></p>
  
  <p>Code for Block.java: <a href="http://pastebin.com/J41DFbF7" rel="nofollow">http://pastebin.com/J41DFbF7</a></p>
  
  <p>I posted pastebin because I figured otherwise it would take way too much space.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: due to request, here is the "important code" from Blocks.java:</p>
  
  <pre><code>package com.matthewpipie.MyCraft;
  
  public class Block extends JPanel {
      private static final int BLOCK_SIZE = 90;
      private int id;
      private int x;
      private int y;
      private Color color;
  
      public Block(int id, int x, int y) {
          this.setUpFrame();
          this.id = id;
          this.x = x;
          this.y = y;
          this.generateColor();
          this.setActionListeners();
      }
  
      public void setUpFrame() {
          this.setPreferredSize(new Dimension(Block.getBLOCK_SIZE(), Block.getBLOCK_SIZE()));
      }
  
      public void setActionListeners() {
          System.out.print("setting up ");
          System.out.println(this.getId());
          this.addMouseListener(new MouseAdapter() {
              public void mouseReleased(MouseEvent e) {
                  System.out.println("clicky45");
              }
          });
      }
  
      **getters and setters*
  }
  </code></pre>
  
  <p>"clicky45" only appears if I click somewhere past a strange vertical invisible line.</p>
  
  <p>EDIT: I figured out that it has something to do with the size of the blocks.  The bigger they all are, the more that can be clicked.  If they are small enough, none of them can be clicked.  </p>