|
@ -39,6 +39,25 @@ public class GridGUI extends JPanel { |
|
|
allShips.add(submarine); |
|
|
allShips.add(submarine); |
|
|
allShips.add(battleship); |
|
|
allShips.add(battleship); |
|
|
allShips.add(aircraftCarrier); |
|
|
allShips.add(aircraftCarrier); |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 1; i < (rows * columns); i++) { |
|
|
|
|
|
BSButton b = new BSButton(); |
|
|
|
|
|
b.setEnabled(false); |
|
|
|
|
|
b.setGridLocation(i); |
|
|
|
|
|
buttons.add(b); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setShipLocations(); |
|
|
|
|
|
|
|
|
|
|
|
GridLayout g = new GridLayout(rows,columns); |
|
|
|
|
|
this.setLayout(g); |
|
|
|
|
|
|
|
|
|
|
|
//Add listeners to all cells in grid to listen for guesses. |
|
|
|
|
|
|
|
|
|
|
|
for (BSButton bsb : buttons) { |
|
|
|
|
|
bsb.addActionListener(new MyCellListener()); |
|
|
|
|
|
this.add(bsb); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
public void setShipLocations() { |
|
|
public void setShipLocations() { |
|
|
|
|
|
|
|
|