JJHT7439 0 Newbie Poster

Alright, I have the bad practice of not commenting my code very often when I write it so I'm going to try to explain what the problem is as clearly as possible. In this program I have to set up a battleship like grid of buttons. In order to determine which spots on the grid hit or miss I have a LinkedList. Each spot on the list holds 1 set of coordinates and an identifier in an int[] (EX: LinkedList.get(0) could be [1,1,9]). The first two numbers are the X and Y coordinates of the piece of the ship, and the last number is the ID for what the ship the piece belongs to. I am currently using this code to populate the grid:

for(int row = 0; row < boardSize; row++){
			for(int col = 0; col < boardSize; col++){
				JButton gridBox = new JButton();
				gridBox.setBorderPainted(true);
				gridBox.setContentAreaFilled(false);
				gridBox.setOpaque(true);
				gridBox.setBackground(Color.BLUE);
				gridBox.addActionListener(this);
				for(int i = 0; i<coordinates.size();i++){
					System.out.println("Row on:" + row);
					System.out.println("Row in file:" + coordinates.get(i)[0]);
					System.out.println("Column on:" + col);
					System.out.println("Column in file: " + coordinates.get(i)[1]);
					if(row == coordinates.get(i)[0] && col == coordinates.get(i)[1] ){
						System.out.println("Winnar");
						gridBox.setActionCommand(Integer.toString(coordinates.get(i)[2]));
					}
					else{
						gridBox.setActionCommand("Miss");
					}
					topGrid.add(gridBox);
				}
			}
		}

(NOTE: The code above has print statements from my testing)

The problem that occurs is that when I run my code and click a grid, only the last piece turns red, because only the last piece has an ActionCommand set to an identifier. I tested my program with the print statements above and found that it does go into the "Winnar" if statement when it is supposed to so it should be setting the ActionCommand correctly. I also tried setting all of the ActionCommands to non-miss outside of the if statement and then everything turns to hit, so I know that the problem is in this code.

Any help would be appreciated.