Battleship Java Program

profilexfire51
battleshipgame_assignment2solution.zip

BattleshipGame_Assignment2Solution/BattleshipGame/build.xml

Builds, tests, and runs the project BattleshipGame.

BattleshipGame_Assignment2Solution/BattleshipGame/build/built-jar.properties

#Tue, 14 Feb 2017 21:22:03 -0500 C\:\\Users\\kwhiting\\Documents\\NetBeansProjects\\BattleshipGame_Assignment5Solution\\BattleshipGame=

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/.netbeans_automatic_build

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/.netbeans_update_resources

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/battleshipgame/BattleshipGame.class

package battleshipgame;
public synchronized class BattleshipGame {
    public void BattleshipGame();
    public static void main(String[]);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Battleship.class

package core;
public synchronized class Battleship extends Ship {
    public void Battleship();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/BattleshipClient$PlayListener.class

package core;
public synchronized class BattleshipClient$PlayListener implements java.awt.event.ActionListener {
    public void BattleshipClient$PlayListener(BattleshipClient);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/BattleshipClient.class

package core;
public synchronized class BattleshipClient {
    public void BattleshipClient();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Carrier.class

package core;
public synchronized class Carrier extends Ship {
    public void Carrier();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Constants.class

package core;
public synchronized class Constants {
    public static final int CARRIER_LENGTH = 5;
    public static final int BATTLESHIP_LENGTH = 4;
    public static final int SUBMARINE__LENGTH = 3;
    public static final int DESTROYER_LENGTH = 3;
    public static final int PATROL_BOAT_LENGTH = 2;
    public static final int CARRIER = 0;
    public static final int BATTLESHIP = 1;
    public static final int SUBMARINE = 2;
    public static final int DESTROYER = 3;
    public static final int PATROL_BOAT = 4;
    public static final int HORIZONTAL = 0;
    public static final int VERTICAL = 1;
    public static final int PLAYER_ONE = 0;
    public static final int PLAYER_TWO = 1;
    public static final int HUMAN = 0;
    public static final int COMPUTER = 1;
    public void Constants();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Destroyer.class

package core;
public synchronized class Destroyer extends Ship {
    public void Destroyer();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/IShip.class

package core;
public abstract interface IShip {
    public static final int MAX_SHIPS = 5;
    public abstract boolean isShipPlaced();
    public abstract void setShipLocation(int, int);
    public abstract int getShipLength();
    public abstract void setShipLength(int);
    public abstract boolean isShipSunk();
    public abstract String getShipName();
    public abstract void setShipName(String);
    public abstract int getHitsLeft();
    public abstract int getMaxHits();
    public abstract void setMaxHits(int);
    public abstract int getShipDirection();
    public abstract void setShipDirection(int);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/PatrolBoat.class

package core;
public synchronized class PatrolBoat extends Ship {
    public void PatrolBoat();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Ship.class

package core;
public synchronized class Ship implements IShip {
    private boolean shipPlaced;
    private boolean shipSunk;
    int hitsLeft;
    int maxNumberOfHits;
    int shipDirection;
    int shipLength;
    private int shipStartRow;
    private int shipStopRow;
    private int shipStartCol;
    private int shipStopCol;
    String shipName;
    public void Ship();
    public boolean isShipPlaced();
    public void setShipPlaced(boolean);
    public void setShipLocation(int, int);
    public int getShipLength();
    public void setShipLength(int);
    public boolean isShipSunk();
    public String getShipName();
    public void setShipName(String);
    public int getHitsLeft();
    public void minusHitsLeft();
    public int getMaxHits();
    public void setMaxHits(int);
    public int getShipDirection();
    public void setShipDirection(int);
    public int getShipStartRow();
    public int getShipStartCol();
    public int getShipStopRow();
    public void setShipStopRow(int);
    public int getShipStopCol();
    public void setShipStopCol(int);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/core/Submarine.class

package core;
public synchronized class Submarine extends Ship {
    public void Submarine();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$1.class

package userInterface;
synchronized class BattleshipUI$1 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$2.class

package userInterface;
synchronized class BattleshipUI$2 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$3.class

package userInterface;
synchronized class BattleshipUI$3 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$4.class

package userInterface;
synchronized class BattleshipUI$4 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$5.class

package userInterface;
synchronized class BattleshipUI$5 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$DirectionListener.class

package userInterface;
synchronized class BattleshipUI$DirectionListener implements java.awt.event.ActionListener {
    private void BattleshipUI$DirectionListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$ExitListener.class

package userInterface;
synchronized class BattleshipUI$ExitListener implements java.awt.event.ActionListener {
    private void BattleshipUI$ExitListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$GameListener.class

package userInterface;
synchronized class BattleshipUI$GameListener implements java.awt.event.ActionListener {
    private void BattleshipUI$GameListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$OptionsListener.class

package userInterface;
synchronized class BattleshipUI$OptionsListener implements java.awt.event.ActionListener {
    GameOptionDialog gameOptions;
    PlayerOptionDialog playerOptions;
    private void BattleshipUI$OptionsListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI$ShipListener.class

package userInterface;
synchronized class BattleshipUI$ShipListener implements java.awt.event.ActionListener {
    private void BattleshipUI$ShipListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/BattleshipUI.class

package userInterface;
public synchronized class BattleshipUI extends javax.swing.JFrame {
    private static javax.swing.JMenuBar menuBar;
    private static javax.swing.JMenu gameMenu;
    private static javax.swing.JMenu optionMenu;
    private static javax.swing.JMenuItem playerPlayer;
    private static javax.swing.JMenuItem playerComputer;
    private static javax.swing.JMenuItem computerComputer;
    private static javax.swing.JMenuItem exit;
    private static javax.swing.JMenuItem game;
    private static javax.swing.JMenuItem player;
    private static javax.swing.JButton deploy;
    private javax.swing.JPanel shipLayoutPanel;
    private static javax.swing.JPanel playerOnePanel;
    private static javax.swing.JPanel playerTwoPanel;
    private static javax.swing.JPanel statusPanel;
    private static javax.swing.JScrollPane scrollPane;
    private static javax.swing.JTextArea textArea;
    private static String[] rowLetters;
    private static String[] columnNumbers;
    private static String[] direction;
    private String[] ships;
    private javax.swing.JComboBox shipCb;
    private javax.swing.JComboBox directionCb;
    private BattleshipUI$GameListener gameListener;
    private BattleshipUI$OptionsListener optionListener;
    private Player playerOne;
    private Player playerTwo;
    private static Player[] players;
    public void BattleshipUI();
    private void initComponents();
    private void setupPlayerPanels();
    private void initObjects();
    private javax.swing.JFrame getThisParent();
    public static void setDeployEnabled(boolean);
    static void <clinit>();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/GameOptionDialog$1.class

package userInterface;
synchronized class GameOptionDialog$1 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/GameOptionDialog$2.class

package userInterface;
synchronized class GameOptionDialog$2 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/GameOptionDialog$CancelListener.class

package userInterface;
synchronized class GameOptionDialog$CancelListener implements java.awt.event.ActionListener {
    private void GameOptionDialog$CancelListener(GameOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/GameOptionDialog$SaveListener.class

package userInterface;
synchronized class GameOptionDialog$SaveListener implements java.awt.event.ActionListener {
    private void GameOptionDialog$SaveListener(GameOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/GameOptionDialog.class

package userInterface;
public synchronized class GameOptionDialog {
    private javax.swing.JDialog dialog;
    private javax.swing.JPanel gameOptionPanel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JLabel computerAiLbl;
    private javax.swing.JLabel shipLayoutLbl;
    private javax.swing.JComboBox computerAi;
    private javax.swing.JComboBox shipLayout;
    private javax.swing.JButton saveBtn;
    private javax.swing.JButton canxBtn;
    private static String[] level;
    private static String[] layout;
    private String selectedLevel;
    private String selectedLayout;
    private Player[] playerArray;
    public void GameOptionDialog(javax.swing.JFrame, Player[]);
    private void initComponents(javax.swing.JFrame);
    static void <clinit>();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/Player$BoardListener.class

package userInterface;
public synchronized class Player$BoardListener implements java.awt.event.ActionListener {
    public void Player$BoardListener(Player);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/Player.class

package userInterface;
public synchronized class Player {
    private boolean isFirst;
    private java.awt.Color shipColor;
    private int currentShip;
    private int currentShipLength;
    private int currentDirection;
    private javax.swing.JButton[][] buttonBoard;
    private String userName;
    private BattleshipUI parent;
    private static final int rows = 10;
    private static final int cols = 10;
    private java.util.ArrayList ships;
    private core.Battleship battleship;
    private core.Carrier carrier;
    private core.Destroyer destroyer;
    private core.PatrolBoat patrolBoat;
    private core.Submarine submarine;
    private Player$BoardListener boardListener;
    public void Player();
    public void Player(String, BattleshipUI);
    public void setParent(BattleshipUI);
    private void initObjects();
    private void initComponents();
    public Player$BoardListener getBoardListener();
    public void setListener(javax.swing.JButton, java.awt.event.ActionListener);
    public void removeListener(javax.swing.JButton, java.awt.event.ActionListener);
    public String getUserName();
    public javax.swing.JButton[][] getBoard();
    public static int getRows();
    public static int getCols();
    public int getCurrentShipLength();
    public void setCurrentShip(int);
    public int getCurrentDirection();
    public void setCurrentDirection(int);
    public boolean isIsFirst();
    public void setIsFirst(boolean);
    public java.awt.Color getShipColor();
    public void setShipColor(java.awt.Color);
    public core.Battleship getBattleship();
    public core.Carrier getCarrier();
    public core.Destroyer getDestroyer();
    public core.PatrolBoat getPatrolBoat();
    public core.Submarine getSubmarine();
    private void placeShip(int, int);
    private void isReadyToDeploy();
    private boolean isValid(int, int);
    private boolean isOccupied(int, int);
    private void removeShip(core.Ship);
    public java.util.ArrayList getShips();
    public int getCurrentShip();
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$1.class

package userInterface;
synchronized class PlayerOptionDialog$1 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$2.class

package userInterface;
synchronized class PlayerOptionDialog$2 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$3.class

package userInterface;
synchronized class PlayerOptionDialog$3 {
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$CancelListener.class

package userInterface;
synchronized class PlayerOptionDialog$CancelListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$CancelListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$PlayerListener.class

package userInterface;
synchronized class PlayerOptionDialog$PlayerListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$PlayerListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog$SaveListener.class

package userInterface;
synchronized class PlayerOptionDialog$SaveListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$SaveListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

BattleshipGame_Assignment2Solution/BattleshipGame/build/classes/userInterface/PlayerOptionDialog.class

package userInterface;
public synchronized class PlayerOptionDialog {
    private javax.swing.JDialog dialog;
    private javax.swing.JPanel playerOptionPanel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JLabel shipColorLbl;
    private javax.swing.JLabel firstPlayerLbl;
    private javax.swing.JComboBox shipColor;
    private javax.swing.JComboBox firstPlayer;
    private javax.swing.JButton saveBtn;
    private javax.swing.JButton canxBtn;
    private javax.swing.JRadioButton player1;
    private javax.swing.JRadioButton player2;
    private javax.swing.ButtonGroup playerOptions;
    private static java.awt.Color[] color;
    private static String[] colors;
    private static String[] players;
    private String selectdColor;
    private String selectedPlayer;
    private Player currentPlayer;
    private Player[] playerArray;
    public void PlayerOptionDialog(javax.swing.JFrame, Player[]);
    private void initComponents(javax.swing.JFrame);
    private void initObjects();
    static void <clinit>();
}

BattleshipGame_Assignment2Solution/BattleshipGame/dist/BattleshipGame.jar

META-INF/MANIFEST.MF

Manifest-Version: 1.0 Ant-Version: Apache Ant 1.9.7 Created-By: 1.8.0_111-b14 (Oracle Corporation) Class-Path: X-COMMENT: Main-Class will be added automatically by build Main-Class: battleshipgame.BattleshipGame

battleshipgame/BattleshipGame.class

package battleshipgame;
public synchronized class BattleshipGame {
    public void BattleshipGame();
    public static void main(String[]);
}

core/Battleship.class

package core;
public synchronized class Battleship extends Ship {
    public void Battleship();
}

core/BattleshipClient$PlayListener.class

package core;
public synchronized class BattleshipClient$PlayListener implements java.awt.event.ActionListener {
    public void BattleshipClient$PlayListener(BattleshipClient);
    public void actionPerformed(java.awt.event.ActionEvent);
}

core/BattleshipClient.class

package core;
public synchronized class BattleshipClient {
    private userInterface.BattleshipUI parent;
    private userInterface.Player[] players;
    private userInterface.Player currentPlayer;
    public void BattleshipClient(userInterface.Player[], userInterface.BattleshipUI);
    private void changeListener();
    public void play();
    private void switchPlayers();
    private boolean checkForWinner();
    private void endGame();
    private void computerPick();
}

core/Carrier.class

package core;
public synchronized class Carrier extends Ship {
    public void Carrier();
}

core/Constants.class

package core;
public synchronized class Constants {
    public static final int CARRIER_LENGTH = 5;
    public static final int BATTLESHIP_LENGTH = 4;
    public static final int SUBMARINE__LENGTH = 3;
    public static final int DESTROYER_LENGTH = 3;
    public static final int PATROL_BOAT_LENGTH = 2;
    public static final int CARRIER = 0;
    public static final int BATTLESHIP = 1;
    public static final int SUBMARINE = 2;
    public static final int DESTROYER = 3;
    public static final int PATROL_BOAT = 4;
    public static final int HORIZONTAL = 0;
    public static final int VERTICAL = 1;
    public static final int PLAYER_ONE = 0;
    public static final int PLAYER_TWO = 1;
    public static final int HUMAN = 0;
    public static final int COMPUTER = 1;
    public void Constants();
}

core/Destroyer.class

package core;
public synchronized class Destroyer extends Ship {
    public void Destroyer();
}

core/IShip.class

package core;
public abstract interface IShip {
    public static final int MAX_SHIPS = 5;
    public abstract boolean isShipPlaced();
    public abstract void setShipLocation(int, int);
    public abstract int getShipLength();
    public abstract void setShipLength(int);
    public abstract boolean isShipSunk();
    public abstract String getShipName();
    public abstract void setShipName(String);
    public abstract int getHitsLeft();
    public abstract int getMaxHits();
    public abstract void setMaxHits(int);
    public abstract int getShipDirection();
    public abstract void setShipDirection(int);
}

core/PatrolBoat.class

package core;
public synchronized class PatrolBoat extends Ship {
    public void PatrolBoat();
}

core/Ship.class

package core;
public synchronized class Ship implements IShip {
    private boolean shipPlaced;
    private boolean shipSunk;
    int hitsLeft;
    int maxNumberOfHits;
    int shipDirection;
    int shipLength;
    private int shipStartRow;
    private int shipStopRow;
    private int shipStartCol;
    private int shipStopCol;
    String shipName;
    public void Ship();
    public boolean isShipPlaced();
    public void setShipPlaced(boolean);
    public void setShipLocation(int, int);
    public int getShipLength();
    public void setShipLength(int);
    public boolean isShipSunk();
    public String getShipName();
    public void setShipName(String);
    public int getHitsLeft();
    public void minusHitsLeft();
    public int getMaxHits();
    public void setMaxHits(int);
    public int getShipDirection();
    public void setShipDirection(int);
    public int getShipStartRow();
    public int getShipStartCol();
    public int getShipStopRow();
    public void setShipStopRow(int);
    public int getShipStopCol();
    public void setShipStopCol(int);
}

core/Submarine.class

package core;
public synchronized class Submarine extends Ship {
    public void Submarine();
}

userInterface/BattleshipUI$1.class

package userInterface;
synchronized class BattleshipUI$1 {
}

userInterface/BattleshipUI$DeployListener.class

package userInterface;
synchronized class BattleshipUI$DeployListener implements java.awt.event.ActionListener {
    private void BattleshipUI$DeployListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI$DirectionListener.class

package userInterface;
synchronized class BattleshipUI$DirectionListener implements java.awt.event.ActionListener {
    private void BattleshipUI$DirectionListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI$ExitListener.class

package userInterface;
synchronized class BattleshipUI$ExitListener implements java.awt.event.ActionListener {
    private void BattleshipUI$ExitListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI$GameListener.class

package userInterface;
synchronized class BattleshipUI$GameListener implements java.awt.event.ActionListener {
    private void BattleshipUI$GameListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI$OptionsListener.class

package userInterface;
synchronized class BattleshipUI$OptionsListener implements java.awt.event.ActionListener {
    GameOptionDialog gameOptions;
    PlayerOptionDialog playerOptions;
    private void BattleshipUI$OptionsListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI$ShipListener.class

package userInterface;
synchronized class BattleshipUI$ShipListener implements java.awt.event.ActionListener {
    private void BattleshipUI$ShipListener(BattleshipUI);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/BattleshipUI.class

package userInterface;
public synchronized class BattleshipUI extends javax.swing.JFrame {
    private static javax.swing.JMenuBar menuBar;
    private static javax.swing.JMenu gameMenu;
    private static javax.swing.JMenu optionMenu;
    private static javax.swing.JMenuItem playerPlayer;
    private static javax.swing.JMenuItem playerComputer;
    private static javax.swing.JMenuItem computerComputer;
    private static javax.swing.JMenuItem exit;
    private static javax.swing.JMenuItem game;
    private static javax.swing.JMenuItem player;
    private static javax.swing.JButton deploy;
    private javax.swing.JPanel shipLayoutPanel;
    private static javax.swing.JPanel playerOnePanel;
    private static javax.swing.JPanel playerTwoPanel;
    private static javax.swing.JPanel statusPanel;
    private static javax.swing.JScrollPane scrollPane;
    private static javax.swing.JTextArea textArea;
    private static String[] rowLetters;
    private static String[] columnNumbers;
    private static String[] direction;
    private String[] ships;
    private javax.swing.JComboBox shipCb;
    private javax.swing.JComboBox directionCb;
    private BattleshipUI$GameListener gameListener;
    private BattleshipUI$OptionsListener optionListener;
    private Player playerOne;
    private Player playerTwo;
    private static Player[] players;
    private core.BattleshipClient gameControl;
    public void BattleshipUI();
    private void initComponents();
    private void setupPlayerPanels();
    public void setDeployEnabled(boolean);
    private void initObjects();
    private javax.swing.JFrame getThisParent();
    public void updateTextArea(String);
    static void <clinit>();
}

userInterface/GameOptionDialog$1.class

package userInterface;
synchronized class GameOptionDialog$1 {
}

userInterface/GameOptionDialog$CancelListener.class

package userInterface;
synchronized class GameOptionDialog$CancelListener implements java.awt.event.ActionListener {
    private void GameOptionDialog$CancelListener(GameOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/GameOptionDialog$SaveListener.class

package userInterface;
synchronized class GameOptionDialog$SaveListener implements java.awt.event.ActionListener {
    private void GameOptionDialog$SaveListener(GameOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/GameOptionDialog.class

package userInterface;
public synchronized class GameOptionDialog {
    private javax.swing.JDialog dialog;
    private javax.swing.JPanel gameOptionPanel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JLabel computerAiLbl;
    private javax.swing.JLabel shipLayoutLbl;
    private javax.swing.JComboBox computerAi;
    private javax.swing.JComboBox shipLayout;
    private javax.swing.JButton saveBtn;
    private javax.swing.JButton canxBtn;
    private static String[] level;
    private static String[] layout;
    private String selectedLevel;
    private String selectedLayout;
    private Player[] playerArray;
    public void GameOptionDialog(javax.swing.JFrame, Player[]);
    private void initComponents(javax.swing.JFrame);
    static void <clinit>();
}

userInterface/Player$BoardListener.class

package userInterface;
public synchronized class Player$BoardListener implements java.awt.event.ActionListener {
    public void Player$BoardListener(Player);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/Player.class

package userInterface;
public synchronized class Player {
    private boolean isFirst;
    private java.awt.Color shipColor;
    private int currentShip;
    private int currentShipLength;
    private int currentDirection;
    private javax.swing.JButton[][] buttonBoard;
    private String userName;
    private BattleshipUI parent;
    private int playMode;
    private static final int rows = 10;
    private static final int cols = 10;
    private java.util.ArrayList ships;
    private core.Battleship battleship;
    private core.Carrier carrier;
    private core.Destroyer destroyer;
    private core.PatrolBoat patrolBoat;
    private core.Submarine submarine;
    private Player$BoardListener boardListener;
    public void Player();
    public void Player(String, BattleshipUI);
    public void setParent(BattleshipUI);
    private void initObjects();
    private void initComponents();
    public Player$BoardListener getBoardListener();
    public void setListener(javax.swing.JButton, java.awt.event.ActionListener);
    public void removeListener(javax.swing.JButton, java.awt.event.ActionListener);
    public String getUserName();
    public javax.swing.JButton[][] getBoard();
    public static int getRows();
    public static int getCols();
    public int getCurrentShipLength();
    public void setCurrentShip(int);
    public int getCurrentDirection();
    public void setCurrentDirection(int);
    public boolean isIsFirst();
    public void setIsFirst(boolean);
    public java.awt.Color getShipColor();
    public void setShipColor(java.awt.Color);
    public core.Battleship getBattleship();
    public core.Carrier getCarrier();
    public core.Destroyer getDestroyer();
    public core.PatrolBoat getPatrolBoat();
    public core.Submarine getSubmarine();
    private void placeShip(int, int);
    private void isReadyToDeploy();
    private boolean isValid(int, int);
    private boolean isOccupied(int, int);
    private void removeShip(core.Ship);
    public java.util.ArrayList getShips();
    public int getCurrentShip();
    public void autoLayout();
    public int getPlayMode();
    public void setPlayMode(int);
    public boolean isHit(int, int);
}

userInterface/PlayerOptionDialog$1.class

package userInterface;
synchronized class PlayerOptionDialog$1 {
}

userInterface/PlayerOptionDialog$CancelListener.class

package userInterface;
synchronized class PlayerOptionDialog$CancelListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$CancelListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/PlayerOptionDialog$PlayerListener.class

package userInterface;
synchronized class PlayerOptionDialog$PlayerListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$PlayerListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/PlayerOptionDialog$SaveListener.class

package userInterface;
synchronized class PlayerOptionDialog$SaveListener implements java.awt.event.ActionListener {
    private void PlayerOptionDialog$SaveListener(PlayerOptionDialog);
    public void actionPerformed(java.awt.event.ActionEvent);
}

userInterface/PlayerOptionDialog.class

package userInterface;
public synchronized class PlayerOptionDialog {
    private javax.swing.JDialog dialog;
    private javax.swing.JPanel playerOptionPanel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JLabel shipColorLbl;
    private javax.swing.JLabel firstPlayerLbl;
    private javax.swing.JComboBox shipColor;
    private javax.swing.JComboBox firstPlayer;
    private javax.swing.JButton saveBtn;
    private javax.swing.JButton canxBtn;
    private javax.swing.JRadioButton player1;
    private javax.swing.JRadioButton player2;
    private javax.swing.ButtonGroup playerOptions;
    private static java.awt.Color[] color;
    private static String[] colors;
    private static String[] players;
    private String selectdColor;
    private String selectedPlayer;
    private Player currentPlayer;
    private Player[] playerArray;
    public void PlayerOptionDialog(javax.swing.JFrame, Player[]);
    private void initComponents(javax.swing.JFrame);
    private void initObjects();
    static void <clinit>();
}

BattleshipGame_Assignment2Solution/BattleshipGame/dist/README.TXT

======================== BUILD OUTPUT DESCRIPTION ======================== When you build an Java application project that has a main class, the IDE automatically copies all of the JAR files on the projects classpath to your projects dist/lib folder. The IDE also adds each of the JAR files to the Class-Path element in the application JAR files manifest file (MANIFEST.MF). To run the project from the command line, go to the dist folder and type the following: java -jar "BattleshipGame.jar" To distribute this project, zip up the dist folder (including the lib folder) and distribute the ZIP file. Notes: * If two JAR files on the project classpath have the same name, only the first JAR file is copied to the lib folder. * Only JAR files are copied to the lib folder. If the classpath contains other types of files or folders, these files (folders) are not copied. * If a library on the projects classpath also has a Class-Path element specified in the manifest,the content of the Class-Path element has to be on the projects runtime path. * To set a main class in a standard Java project, right-click the project node in the Projects window and choose Properties. Then click Run and enter the class name in the Main Class field. Alternatively, you can manually type the class name in the manifest Main-Class element.

BattleshipGame_Assignment2Solution/BattleshipGame/manifest.mf

Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/build-impl.xml

Must set src.dir Must set test.src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: java -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/genfiles.properties

build.xml.data.CRC32=c5594e31 build.xml.script.CRC32=21d5da2e [email protected] # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=c5594e31 nbproject/build-impl.xml.script.CRC32=a5e4e12d nbproject/[email protected]

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/private/private.properties

compile.on.save=true user.properties.file=C:\\Users\\kwhiting\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/private/private.xml

file:/C:/Users/kwhiting/Documents/NetBeansProjects/BattleshipGame_Assignment5Solution/BattleshipGame/src/userInterface/Player.java file:/C:/Users/kwhiting/Documents/NetBeansProjects/BattleshipGame_Assignment5Solution/BattleshipGame/src/userInterface/BattleshipUI.java

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/project.properties

annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processor.options= annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # Files in build.classes.dir which should be excluded from distribution jar dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/BattleshipGame.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= includes=** jar.compress=false javac.classpath= # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.processorpath=\ ${javac.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= main.class=battleshipgame.BattleshipGame manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false platform.active=default_platform run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} # Space-separated list of JVM arguments used when running the project. # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. # To set system properties for unit tests define test-sys-prop.name=value: run.jvmargs= run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src test.src.dir=test

BattleshipGame_Assignment2Solution/BattleshipGame/nbproject/project.xml

org.netbeans.modules.java.j2seproject BattleshipGame

BattleshipGame_Assignment2Solution/BattleshipGame/src/battleshipgame/BattleshipGame.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/battleshipgame/BattleshipGame.java

package  battleshipgame ;

import  userInterface . BattleshipUI ;

// This is the main class that is the entry point into the game
public   class   BattleshipGame  
{    
     public   static   void  main ( String []  args )
     {        
         BattleshipUI  battleship  =   new   BattleshipUI ();  
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Battleship.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Battleship.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Battleship   extends   Ship  
{
     public   Battleship ()
     {
        setShipLength ( Constants . BATTLESHIP_LENGTH );
        setShipName ( "Battleship" );
        setMaxHits ( Constants . BATTLESHIP_LENGTH );
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/BattleshipClient.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/BattleshipClient.java

package  core ;

public   class   BattleshipClient  
{

}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Carrier.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Carrier.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Carrier   extends   Ship  
{
     public   Carrier ()
     {
        setShipLength ( Constants . CARRIER_LENGTH );
        setShipName ( "Carrier" );
        setMaxHits ( Constants . CARRIER_LENGTH );
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Constants.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Constants.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Constants  
{
     // constants for ship lengths
     public   static   final   int  CARRIER_LENGTH  =   5 ;
     public   static   final   int  BATTLESHIP_LENGTH  =   4 ;
     public   static   final   int  SUBMARINE__LENGTH  =   3 ;
     public   static   final   int  DESTROYER_LENGTH  =   3 ;
     public   static   final   int  PATROL_BOAT_LENGTH  =   2 ;    
    
     // constants for ship reference
     public   static   final   int  CARRIER  =   0 ;
     public   static   final   int  BATTLESHIP  =   1 ;
     public   static   final   int  SUBMARINE  =   2 ;
     public   static   final   int  DESTROYER  =   3 ;
     public   static   final   int  PATROL_BOAT  =   4 ;    

     // constants for ship direction
     public   static   final   int  HORIZONTAL  =   0 ;
     public   static   final   int  VERTICAL  =   1 ;     
    
     // constants for the players in the array
     public   static   final   int  PLAYER_ONE  =   0 ;
     public   static   final   int  PLAYER_TWO  =   1 ;

     // constants for the play mode
     public   static   final   int  HUMAN  =   0 ;
     public   static   final   int  COMPUTER  =   1 ;
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Destroyer.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Destroyer.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Destroyer   extends   Ship  
{
     public   Destroyer ()
     {
        setShipLength ( Constants . DESTROYER_LENGTH );
        setShipName ( "Destroyer" );
        setMaxHits ( Constants . DESTROYER_LENGTH );
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/IShip.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/IShip.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

public   interface   IShip  
{   

     public   static   final   int  MAX_SHIPS  =   5 ;
    
     // method signatures
     // similar to a function prototype in C
     // no implementation
     boolean  isShipPlaced ();
     void  setShipLocation ( int  row ,   int  column );
    
     int  getShipLength ();
     void  setShipLength ( int  inLength );
    
     boolean  isShipSunk ();
    
     String  getShipName ();
     void  setShipName ( String  inName );
    
     int  getHitsLeft ();
     int  getMaxHits ();
     void  setMaxHits ( int  inHits );
   
     int  getShipDirection ();
     void  setShipDirection ( int  inDirection );
    
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/PatrolBoat.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/PatrolBoat.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   PatrolBoat   extends   Ship  
{
     public   PatrolBoat ()
     {
        setShipLength ( Constants . PATROL_BOAT_LENGTH );
        setShipName ( "Patrol Boat" );
        setMaxHits ( Constants . PATROL_BOAT_LENGTH );         
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Ship.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Ship.java

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Ship   implements   IShip
{
     private   boolean  shipPlaced ;
     private   boolean  shipSunk ;
    
     int  hitsLeft ;
     int  maxNumberOfHits ;
     int  shipDirection ;
     int  shipLength ;
     private   int  shipStartRow ;
     private   int  shipStopRow ;
     private   int  shipStartCol ;
     private   int  shipStopCol ;
    
     String  shipName ;     
    
    @ Override
//    boolean isShipPlaced();
     public   boolean  isShipPlaced ()  
     {
         return  shipPlaced ;
     }
    
     public   void  setShipPlaced ( boolean  inValue )  
     {
        shipPlaced  =  inValue ;
     }

    @ Override
     public   void  setShipLocation ( int  row ,   int  column )
     {        
        shipStartRow  =  row ;
        shipStartCol  =  column ;
        
         if ( getShipDirection ()   ==   Constants . HORIZONTAL )
         {
            setShipStopRow ( shipStartRow );
            setShipStopCol ( shipStartCol  +   ( getShipLength ()   -   1 ));
         }
         else   if ( getShipDirection ()   ==   Constants . VERTICAL )
         {
            setShipStopRow ( shipStartRow  +   ( getShipLength ()   -   1 ));
            setShipStopCol ( shipStartCol );
         }
     }

    @ Override
     public   int  getShipLength ()  
     {
         return  shipLength ;
     }
    
    @ Override
     public   void  setShipLength ( int  inLength )
     {
        shipLength  =  inLength ;
     }

    @ Override
     public   boolean  isShipSunk ()  
     {
         return  shipSunk ;
     }
    
    @ Override
     public   String  getShipName ()
     {
         return  shipName ;
     }
    
    @ Override
     public   void  setShipName ( String  inName )
     {
        shipName  =  inName ;
     }
    
    @ Override
     public   int  getHitsLeft ()
     {
         return  hitsLeft ;
     }
    
     public   void  minusHitsLeft ()
     {
        hitsLeft -- ;

         if ( hitsLeft  ==   0 )
            shipSunk  =   true ;
     }

    @ Override
     public   int  getMaxHits ()
     {
         return  maxNumberOfHits ;
     }
    
    @ Override
     public   void  setMaxHits ( int  inHits )
     {
        maxNumberOfHits  =  inHits ;
        hitsLeft  =  inHits ;
     }
    
    @ Override
     public   int  getShipDirection ()
     {
         return  shipDirection ;
     }
    
    @ Override
     public   void  setShipDirection ( int  inDirection )
     {
        shipDirection  =  inDirection ;
     }

     /**
     *  @return  the shipStartRow
     */
     public   int  getShipStartRow ()  
     {
         return  shipStartRow ;
     }

     /**
     *  @return  the shipStartCol
     */
     public   int  getShipStartCol ()  
     {
         return  shipStartCol ;
     }     

     /**
     *  @return  the shipStopRow
     */
     public   int  getShipStopRow ()  
     {
         return  shipStopRow ;
     }

     /**
     *  @param  shipStopRow the shipStopRow to set
     */
     public   void  setShipStopRow ( int  shipStopRow )  
     {
         this . shipStopRow  =  shipStopRow ;
     }

     /**
     *  @return  the shipStopCol
     */
     public   int  getShipStopCol ()  
     {
         return  shipStopCol ;
     }

     /**
     *  @param  shipStopCol the shipStopCol to set
     */
     public   void  setShipStopCol ( int  shipStopCol )  
     {
         this . shipStopCol  =  shipStopCol ;
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Submarine.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/core/Submarine.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package  core ;

/**
 *
 *  @author  kwhiting
 */
public   class   Submarine   extends   Ship
{
     public   Submarine ()
     {
        setShipLength ( Constants . SUBMARINE__LENGTH );
        setShipName ( "Submarine" );
        setMaxHits ( Constants . SUBMARINE__LENGTH );             
     }
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/BattleshipUI.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/BattleshipUI.java

package  userInterface ;

import  java . awt . * ;
//import java.awt.event.*;
import  javax . swing . * ;
import  javax . swing . border . BevelBorder ;

import  core . Constants ;
import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;

// This class creates the user interface

public   class   BattleshipUI   extends   JFrame
{        
     // Menu components
     private   static   JMenuBar  menuBar ;     
     private   static   JMenu  gameMenu ;
     private   static   JMenu  optionMenu ;
     private   static   JMenuItem  playerPlayer ;
     private   static   JMenuItem  playerComputer ;
     private   static   JMenuItem  computerComputer ;   
     private   static   JMenuItem  exit ;   
     private   static   JMenuItem  game ;
     private   static   JMenuItem  player ;
    
     // Buttons
     private   static   JButton  deploy ;

     // Lay out the UI  
     private   JPanel  shipLayoutPanel ;
     private   static   JPanel  playerOnePanel ;
     private   static   JPanel  playerTwoPanel ;
     private   static   JPanel  statusPanel ;
     private   static   JScrollPane  scrollPane ;
     private   static   JTextArea  textArea ;

     // Data arrays for various components on the UI
     private   static   String []  rowLetters  =   { " " , "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" };
     private   static   String []  columnNumbers  =   { " " , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" };
     private   static   String []  direction  =   { "Horizontal" , "Vertical" };
     private   String []  ships  =   { "Carrier" , "Battleship" , "Submarine" , "Destroyer" ,   "Patrol Boat" };

     // ComboBoxes
     private   JComboBox  shipCb ;
     private   JComboBox  directionCb ;

     // event handlers
     private   GameListener  gameListener ;
     private   OptionsListener  optionListener ;

     // Objects
     private   Player  playerOne ;
     private   Player  playerTwo ;
     private   static   Player []  players  =   new   Player [ 2 ];

     // Custom constructor for Battleship class that calls initComponents to 
     // set up the user interface
     public   BattleshipUI ()
     {
        initObjects ();
        initComponents ();
     }

     // layout the user interface
     private   void  initComponents ()
     {    
         this . setTitle ( "Battleship" );         
         this . setDefaultCloseOperation ( EXIT_ON_CLOSE );
         this . setPreferredSize ( new   Dimension ( 500 ,   500 ));
         this . setMinimumSize ( new   Dimension ( 500 ,   500 ));
        
         //create menubar, menu, submenu, and menuitems
        menuBar  =   new   JMenuBar ();
        gameMenu  =   new   JMenu ( "Game" );
        gameMenu . setMnemonic ( 'G' );
        optionMenu  =   new   JMenu ( "Options" );
        optionMenu . setMnemonic ( 'O' );
        menuBar . add ( gameMenu );
        menuBar . add ( optionMenu );
         this . setJMenuBar ( menuBar );

         //game menu
        gameListener  =   new   GameListener ();
        
        playerPlayer  =   new   JMenuItem ( "Player vs. Player" );       
        playerPlayer . addActionListener ( gameListener );
        playerPlayer . setEnabled ( false );
        gameMenu . add ( playerPlayer );

        playerComputer  =   new   JMenuItem ( "Player vs. Computer" );
        playerComputer . addActionListener ( gameListener );
        playerComputer . setSelected ( true );
        gameMenu . add ( playerComputer );

        computerComputer  =   new   JMenuItem ( "Computer vs. Computer" );
        computerComputer . addActionListener ( gameListener );
        computerComputer . setEnabled ( false );
        gameMenu . add ( computerComputer );

        exit  =   new   JMenuItem ( "Exit" );
        exit . addActionListener ( new   ExitListener ());
        gameMenu . add ( exit );  
        
         // options menu 
        optionListener  =   new   OptionsListener ();
        
        game  =   new   JMenuItem ( "Game Options" );
        game . addActionListener ( optionListener );      
        optionMenu . add ( game );
        
        player  =   new   JMenuItem ( "Player Options" );
        player . addActionListener ( optionListener );        
        optionMenu . add ( player );
        
         // buttons
        deploy  =   new   JButton ( "Deploy Ships" );
        deploy . setEnabled ( false );
               
        shipCb  =   new   JComboBox ();

         for ( String  ship  :  ships )
         {
            shipCb . addItem ( ship );    
         }         
        
        shipCb . addActionListener ( new   ShipListener ());
        shipCb . setSelectedIndex ( 0 );
        
        directionCb  =   new   JComboBox ( direction );
        directionCb . addActionListener ( new   DirectionListener ());
        directionCb . setSelectedIndex ( 0 );
        
         // set up the ship layout panel
        shipLayoutPanel  =   new   JPanel ( new   FlowLayout ());
        shipLayoutPanel . setBorder ( BorderFactory . createTitledBorder ( "Select Ship and Direction" ));
        shipLayoutPanel . add ( shipCb );
        shipLayoutPanel . add ( directionCb );
        shipLayoutPanel . add ( deploy );
        
        setupPlayerPanels ();        

         // Status panel setup
        statusPanel  =   new   JPanel ();
        statusPanel . setBorder ( BorderFactory . createTitledBorder ( "Game Status" ));
        textArea  =   new   JTextArea ();
        textArea . setLineWrap ( true );
        scrollPane  =   new   JScrollPane ( textArea );
        scrollPane . setPreferredSize ( new   Dimension ( 180 ,   350 ));
        scrollPane . setHorizontalScrollBarPolicy ( JScrollPane . HORIZONTAL_SCROLLBAR_NEVER );
        scrollPane . setVerticalScrollBarPolicy ( JScrollPane . VERTICAL_SCROLLBAR_AS_NEEDED );
        statusPanel . add ( scrollPane );

         this . add ( shipLayoutPanel ,   BorderLayout . NORTH );
         this . add ( playerOnePanel ,   BorderLayout . WEST );
         this . setVisible ( true );
     }    
    
     private   void  setupPlayerPanels ()
     {
         // set up Player 1 display
        playerOnePanel  =   new   JPanel ( new   GridLayout ( 11 ,   11 ));
        playerOnePanel . setMinimumSize ( new   Dimension ( 400 ,   400 ));
        playerOnePanel . setPreferredSize ( new   Dimension ( 400 ,   400 ));
        playerOnePanel . setBorder ( BorderFactory . createTitledBorder ( "Player One" ));
        
         // Get player one's JButton array
         JButton [][]  playerOneArray  =  playerOne . getBoard ();
        
         // The GridLayout is 11 x 11 but the JButton array is only 10 x 10
         // need to account for the first row being the numbers 1 - 10
         // and the first column being letters A - J
         for ( int  row  =   0 ;  row  <=  playerOne . getRows ();  row ++ )
         {
             for ( int  col  =   0 ;  col  <=  playerOne . getCols ();  col ++ )
             {
                 // The first row displays the numbers
                 if ( row  ==   0 )
                 {
                     JLabel  colLabel  =   new   JLabel ( columnNumbers [ col ],   SwingConstants . CENTER );
                    colLabel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
                    playerOnePanel . add ( colLabel );
                 }
                 // now have to consider the first col is a letter for each row > 0
                 else   if ( row  >   0   &&  col  ==   0 )
                 {
                     JLabel  rowLabel  =   new   JLabel ( rowLetters [ row ],   SwingConstants . CENTER );
                    rowLabel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
                    playerOnePanel . add ( rowLabel );
                 }
                 else
                 {
                    playerOnePanel . add ( playerOneArray [ row  -   1 ][ col  -   1 ]);
                 }
             }
         }
     }
       
     private   void  initObjects ()
     {
         // Initialize the player objects and add them to the array
        playerOne  =   new   Player ( "Player 1" ,   this );
        playerTwo  =   new   Player ( "Player 2" ,   this );
        
        players [ Constants . PLAYER_ONE ] =  playerOne ;
        players [ Constants . PLAYER_TWO ] =  playerTwo ;                                

     }
    
     private   JFrame  getThisParent ()
     {
         return   this ;
     }
    
     public   static   void  setDeployEnabled ( boolean  deployed )  
     {
        deploy . setEnabled ( deployed );
     }      // exit menu item selected
    
     private   class   ExitListener   implements   ActionListener
     {
         public   void  actionPerformed ( ActionEvent  e )
         {
             int  response  =   JOptionPane . showConfirmDialog ( null ,   "Confirm to exit Battleship?" ,  
                     "Exit?" ,   JOptionPane . YES_NO_OPTION );
            
             if   ( response  ==   JOptionPane . YES_OPTION )
                 System . exit ( 0 );  
         }    
     }

     //listener for game menu selection      
     private   class   GameListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
             if ( e . getActionCommand (). equals ( "Player vs. Player" ))                    
             {
             }
             else   if ( e . getActionCommand (). equals ( "Player vs. Computer" ))
             {
             }
             else   if ( e . getActionCommand (). equals ( "Computer vs. Computer" ))
             {
             }
         }    
     }    
    
     //Listener for Options menu
     private   class   OptionsListener   implements   ActionListener
     {    
         GameOptionDialog  gameOptions ;
         PlayerOptionDialog  playerOptions ;

         public   void  actionPerformed ( ActionEvent  e )  
         {
             if ( e . getActionCommand (). equals ( "Game Options" ))
                gameOptions  =   new   GameOptionDialog ( getThisParent (),  players );
             else   if ( e . getActionCommand (). equals ( "Player Options" ))
                playerOptions  =   new   PlayerOptionDialog ( getThisParent (),  players );
         }
     }    

     private   class   ShipListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )  
         {
             int  index  =  shipCb . getSelectedIndex ();
            
             if ( shipCb . getSelectedItem (). equals ( "Carrier" )   )
                playerOne . setCurrentShip ( Constants . CARRIER );
             else   if   ( shipCb . getSelectedItem (). equals ( "Battleship" ))
                playerOne . setCurrentShip ( Constants . BATTLESHIP );
             else   if   ( shipCb . getSelectedItem (). equals ( "Submarine" ))
                playerOne . setCurrentShip ( Constants . SUBMARINE );
             else   if   ( shipCb . getSelectedItem (). equals ( "Destroyer" ))
                playerOne . setCurrentShip ( Constants . DESTROYER );
             else   if   ( shipCb . getSelectedItem (). equals ( "Patrol Boat" ))
                playerOne . setCurrentShip ( Constants . PATROL_BOAT );
         }    
     }    

     private   class   DirectionListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )  
         {
             if ( directionCb . getSelectedItem (). equals ( "Horizontal" )   )
                playerOne . setCurrentDirection ( Constants . HORIZONTAL );
             else   if   ( directionCb . getSelectedItem (). equals ( "Vertical" ))
                playerOne . setCurrentDirection ( Constants . VERTICAL );
         }    
     }    
        
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/GameOptionDialog.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/GameOptionDialog.java

package  userInterface ;

import  java . awt . BorderLayout ;
import  java . awt . Dimension ;
import  java . awt . GridLayout ;
import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;
import  javax . swing . BorderFactory ;
import  javax . swing . JButton ;
import  javax . swing . JComboBox ;
import  javax . swing . JDialog ;
import  javax . swing . JFrame ;
import  javax . swing . JLabel ;
import  javax . swing . JPanel ;
import  javax . swing . border . BevelBorder ;

public   class   GameOptionDialog  
{
     private   JDialog  dialog ;
     private   JPanel  gameOptionPanel ;
     private   JPanel  optionsPanel ;
     private   JPanel  buttonPanel ;
     private   JLabel  computerAiLbl ;
     private   JLabel  shipLayoutLbl ;
     private   JComboBox  computerAi ;
     private   JComboBox  shipLayout ;
     private   JButton  saveBtn ;
     private   JButton  canxBtn ;
    
     private   static   String []  level  =   { "Normal" ,   "Ridiculously Hard" };  
     private   static   String []  layout  =   { "Manual" , "Automatic" };

     private   String  selectedLevel ;  
     private   String  selectedLayout ;
  
     private   Player []  playerArray ;
    
     public   GameOptionDialog ( JFrame  parent ,   Player []  inPlayers )
     {
        playerArray  =  inPlayers ;
        initComponents ( parent );
     }
    
     private   void  initComponents ( JFrame  parent )
     {
         // Dialog
        dialog  =   new   JDialog ( parent ,   true );
        dialog . setDefaultCloseOperation ( JDialog . DISPOSE_ON_CLOSE );
        
         // Options panels
        optionsPanel  =   new   JPanel ();
        optionsPanel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
        gameOptionPanel  =   new   JPanel ( new   GridLayout ( 2 ,   2 ));
        gameOptionPanel . setBorder ( BorderFactory . createTitledBorder ( "Game Options" ));
        gameOptionPanel . setPreferredSize ( new   Dimension ( 275 ,   100 ));
        
         // gameOptionPanel
        computerAiLbl  =   new   JLabel ( "Computer AI" );
        gameOptionPanel . add ( computerAiLbl );
        computerAi  =   new   JComboBox ( level );
        computerAi . setSelectedIndex ( 0 );          
        gameOptionPanel . add ( computerAi );
        
        shipLayoutLbl  =   new   JLabel ( "Ship Layout" );
        gameOptionPanel . add ( shipLayoutLbl );
        shipLayout  =   new   JComboBox ( layout );
        shipLayout . setSelectedIndex ( 0 );          
        gameOptionPanel . add ( shipLayout );
        
         // optionsPanel
        optionsPanel . add ( gameOptionPanel );
        
         // Button Panel
        saveBtn  =   new   JButton ( "Save" );
        saveBtn . addActionListener ( new   SaveListener ());       
        
        canxBtn  =   new   JButton ( "Cancel" );
        canxBtn . addActionListener ( new   CancelListener ());         
        
        buttonPanel  =   new   JPanel ();
        buttonPanel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
        buttonPanel . add ( saveBtn );
        buttonPanel . add ( canxBtn );
        
         // Final setup
        dialog . setTitle ( "Options" );
        dialog . setLayout ( new   BorderLayout ());         
        dialog . getContentPane (). add ( optionsPanel ,   BorderLayout . CENTER );
        dialog . getContentPane (). add ( buttonPanel ,   BorderLayout . SOUTH );
        dialog . setMinimumSize ( new   Dimension ( 300 ,   190 ));
        dialog . setLocation ( 200 , 200 );
        dialog . setVisible ( true );         
     }
    
     //Listener for ok button in statistics menu
     private   class   SaveListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
            dialog . dispose ();
         }             
     }    

     private   class   CancelListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
            dialog . dispose ();
         }    
     }    
    
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/Player.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/Player.java

package  userInterface ;

import  java . awt . * ;
import  javax . swing . * ;

import  core . * ;
import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;
import  java . util . ArrayList ;
import  java . util . Random ;

public   class   Player  
{
     // Class members
     private   boolean  isFirst ;
     private   Color  shipColor ;
     private   int  currentShip ;
     private   int  currentShipLength ;
     private   int  currentDirection ;
     private   JButton [][]  buttonBoard ;
    
     // instance variable 
     private   String  userName ;
    
     private   BattleshipUI  parent ;
    
     private   final   static   int  rows  =   10 ;
     private   final   static   int  cols  =   10 ;
    
     private   ArrayList < Ship >  ships ;
     private   Battleship  battleship ;
     private   Carrier  carrier ;
     private   Destroyer  destroyer ;
     private   PatrolBoat  patrolBoat ;
     private   Submarine  submarine ;
    
     private   BoardListener  boardListener ;
    
     public   Player ()
     {
     }
    
     public   Player ( String  name ,   BattleshipUI  inParent )
     {            
        parent  =  inParent ;
        userName  =  name ;
 
        initObjects ();
        initComponents ();
     }    

     public   void  setParent ( BattleshipUI  inParent )
     {
        parent  =  inParent ;
     }
    
     private   void  initObjects ()
     {
        ships  =   new   ArrayList < Ship > ();
        
        carrier  =   new   Carrier ();
        ships . add ( Constants . CARRIER ,  carrier );
        battleship  =   new   Battleship ();
        ships . add ( Constants . BATTLESHIP ,  battleship );
        submarine  =   new   Submarine ();
        ships . add ( Constants . SUBMARINE ,  submarine );
        destroyer  =   new   Destroyer ();
        ships . add ( Constants . DESTROYER ,  destroyer );
        patrolBoat  =   new   PatrolBoat ();
        ships . add ( Constants . PATROL_BOAT ,  patrolBoat );
        
        boardListener  =   new   BoardListener ();
     }
    
     private   void  initComponents ()
     {
        buttonBoard  =   new   JButton   [ 10 ][ 10 ];         
        
         for   ( int  row  =   0 ;  row  <   10 ;  row ++ )
         {            
             for   ( int  col  =   0 ;  col  <   10 ;  col ++ )
             {
                buttonBoard [ row ][ col ]   =   new   JButton ();
                buttonBoard [ row ][ col ]. putClientProperty ( "row" ,  row );
                buttonBoard [ row ][ col ]. putClientProperty ( "col" ,  col );
                setListener ( buttonBoard [ row ][ col ],  boardListener );
             }
         }    
     }
    
     public   BoardListener  getBoardListener ()
     {
         return  boardListener ;
     }
    
     public   void  setListener ( JButton  inButton ,   ActionListener  inListener )
     {
        inButton . addActionListener ( inListener );
     }

     public   void  removeListener ( JButton  inButton ,   ActionListener  inListnener )
     {
        inButton . removeActionListener ( inListnener );
     }
    
     public   String  getUserName ()
     {
         return  userName ;
     }
    
     public   JButton [][]  getBoard ()
     {
         return  buttonBoard ;
     }

     /**
     *  @return  the rows
     */
     public   static   int  getRows ()  
     {
         return  rows ;
     }

     /**
     *  @return  the cols
     */
     public   static   int  getCols ()  
     {
         return  cols ;
     }

     /**
     *  @return  the currentShip
     */
     public   int  getCurrentShipLength ()  
     {
         return  currentShipLength ;
     }

     /**
     *  @param  currentShip the currentShip to set
     */
     public   void  setCurrentShip ( int  currentShip )
     {
         this . currentShip  =  currentShip ;
        
         if ( currentShip  ==   Constants . BATTLESHIP )
            currentShipLength  =   Constants . BATTLESHIP_LENGTH ;
         else   if ( currentShip  ==   Constants . CARRIER )
            currentShipLength  =   Constants . CARRIER_LENGTH ;
         else   if ( currentShip  ==   Constants . DESTROYER )
            currentShipLength  =   Constants . DESTROYER_LENGTH ;
         else   if ( currentShip  ==   Constants . PATROL_BOAT )
            currentShipLength  =   Constants . PATROL_BOAT_LENGTH ;
         else   if ( currentShip  ==   Constants . SUBMARINE )
            currentShipLength  =   Constants . SUBMARINE__LENGTH ;
     }

     /**
     *  @return  the currentDirection
     */
     public   int  getCurrentDirection ()  
     {
         return  currentDirection ;
     }

     /**
     *  @param  currentDirection the currentDirection to set
     */
     public   void  setCurrentDirection ( int  currentDirection )  
     {
         this . currentDirection  =  currentDirection ;
     }
    
     /**
     *  @return  the isFirst
     */
     public   boolean  isIsFirst ()  
     {
         return  isFirst ;
     }

     /**
     *  @param  isFirst the isFirst to set
     */
     public   void  setIsFirst ( boolean  isFirst )  
     {
         this . isFirst  =  isFirst ;
     }

     /**
     *  @return  the shipColor
     */
     public   Color  getShipColor ()  
     {
         return  shipColor ;
     }

     /**
     *  @param  shipColor the shipColor to set
     */
     public   void  setShipColor ( Color  shipColor )  
     {
         this . shipColor  =  shipColor ;
     }
    
     /**
     *  @return  the battleship
     */
     public   Battleship  getBattleship ()  
     {
         return  battleship ;
     }

     /**
     *  @return  the carrier
     */
     public   Carrier  getCarrier ()  
     {
         return  carrier ;
     }

     /**
     *  @return  the destroyer
     */
     public   Destroyer  getDestroyer ()  
     {
         return  destroyer ;
     }

     /**
     *  @return  the patrolBoat
     */
     public   PatrolBoat  getPatrolBoat ()  
     {
         return  patrolBoat ;
     }

     /**
     *  @return  the submarine
     */
     public   Submarine  getSubmarine ()  
     {
         return  submarine ;
     }

     private   void  placeShip ( int  rowClick ,   int  colClick )
     {
         if ( getCurrentShip ()   ==   Constants . BATTLESHIP  &&  getBattleship (). isShipPlaced ())
         {
            removeShip ( getBattleship ());
         }
         else   if ( getCurrentShip ()   ==   Constants . CARRIER  &&  getCarrier (). isShipPlaced ())
         {
            removeShip ( getCarrier ());
         }
         else   if ( getCurrentShip ()   ==   Constants . DESTROYER  &&  getDestroyer (). isShipPlaced ())
         {
            removeShip ( getDestroyer ());
         }
         else   if ( getCurrentShip ()   ==   Constants . PATROL_BOAT  &&  getPatrolBoat (). isShipPlaced ())
         {
            removeShip ( getPatrolBoat ());
         }
         else   if ( getCurrentShip ()   ==   Constants . SUBMARINE  &&  getSubmarine (). isShipPlaced ())
         {
            removeShip ( getSubmarine ());
         }

         switch (  getCurrentDirection ()   )
         {
             case   Constants . VERTICAL :
             {         
                 for ( int  row  =  rowClick ;  row  <   ( rowClick  +  getCurrentShipLength ());  row ++ )
                 {
                    buttonBoard [ row ][ colClick ]. setBackground ( getShipColor ());
                 }

                 break ;
             }
             case   Constants . HORIZONTAL :
             {
                 for ( int  col  =  colClick ;  col  <   ( colClick  +  getCurrentShipLength ());  col ++ )
                 {
                    buttonBoard [ rowClick ][ col ]. setBackground ( getShipColor ());
                 }
                
                 break ;
             }
         }

         if ( getCurrentShip ()   ==   Constants . BATTLESHIP )
         {
            getBattleship (). setShipDirection ( getCurrentDirection ());
            getBattleship (). setShipLocation ( rowClick ,  colClick );
            getBattleship (). setShipPlaced ( true );
         }
         else   if ( getCurrentShip ()   ==   Constants . CARRIER )
         {
            getCarrier (). setShipDirection ( getCurrentDirection ());
            getCarrier (). setShipLocation ( rowClick ,  colClick );
            getCarrier (). setShipPlaced ( true );
         }
         else   if ( getCurrentShip ()   ==   Constants . DESTROYER )
         {
            getDestroyer (). setShipDirection ( getCurrentDirection ());
            getDestroyer (). setShipLocation ( rowClick ,  colClick );
            getDestroyer (). setShipPlaced ( true );
         }
         else   if ( getCurrentShip ()   ==   Constants . PATROL_BOAT )
         {
            getPatrolBoat (). setShipDirection ( getCurrentDirection ());
            getPatrolBoat (). setShipLocation ( rowClick ,  colClick );
            getPatrolBoat (). setShipPlaced ( true );
         }
         else   if ( getCurrentShip ()   ==   Constants . SUBMARINE )
         {
            getSubmarine (). setShipDirection ( getCurrentDirection ());
            getSubmarine (). setShipLocation ( rowClick ,  colClick );
            getSubmarine (). setShipPlaced ( true );
         }                         

         if ( getUserName (). equals ( "Player 1" ))
         {
            isReadyToDeploy ();
         }
     }
    
     private   void  isReadyToDeploy ()
     {
         if (  getBattleship (). isShipPlaced ()   ==   true   &&  
            getCarrier (). isShipPlaced ()   ==   true   &&  
            getDestroyer (). isShipPlaced ()   ==   true   &&  
            getPatrolBoat (). isShipPlaced ()   ==   true   &&
            getSubmarine (). isShipPlaced ()   ==   true )
         {
            parent . setDeployEnabled ( true );
         }
     }

     private   boolean  isValid ( int  rowClick ,   int  colClick )
     {
         switch (  getCurrentDirection ()   )
         {
             case   Constants . VERTICAL :
             {
                 if (   ( rowClick  +  getCurrentShipLength ())   >  getRows ()   )
                 {
                     return   false ;
                 }
                
                 break ;
             }
             case   Constants . HORIZONTAL :
             {
                 if (   ( colClick  +  getCurrentShipLength ())   >  getCols ()   )
                 {
                     return   false ;
                 }
                
                 break ;
             }
         }
        
         return   true ;
     }

     private   boolean  isOccupied ( int  rowClick ,   int  colClick )
     {
         switch (  getCurrentDirection ()   )
         {
             case   Constants . VERTICAL :
             {
                 for ( int  row  =  rowClick ;  row  <  rowClick  +  getCurrentShipLength ();  row  ++ )
                 {
                     if ( buttonBoard [ row ][ colClick ]. getBackground ()   ==  shipColor )
                     {
                         return   true ;
                     }
                 }
                
                 break ;
             }
             case   Constants . HORIZONTAL :
             {
                 for ( int  col  =  colClick ;  col  <  colClick  +  getCurrentShipLength ();  col  ++ )
                 {
                     if ( buttonBoard [ rowClick ][ col ]. getBackground ()   ==  shipColor )
                     {
                         return   true ;
                     }
                 }
                 break ;
             }
         }
        
         return   false ;
     }
    
     private   void  removeShip ( Ship  inShip )
     {
         switch (  inShip . getShipDirection ()   )
         {
             case   Constants . VERTICAL :
             {
                 for ( int  row  =  inShip . getShipStartRow ();  row  <   ( inShip . getShipStartRow ()   +  inShip . getShipLength ());  row ++ )
                 {
                    buttonBoard [ row ][ inShip . getShipStartCol ()]. setBackground ( null );
                 }
                
                 break ;
             }
             case   Constants . HORIZONTAL :
             {
                 for ( int  col  =  inShip . getShipStartCol ();  col  <   ( inShip . getShipStartCol ()   +  inShip . getShipLength ());  col ++ )
                 {
                    buttonBoard [ inShip . getShipStartRow ()][ col ]. setBackground ( null );    

                 }
                 break ;
             }                
         }
        
        inShip . setShipPlaced ( false );
     }

     /**
     *  @return  the ships
     */
     public   ArrayList < Ship >  getShips ()  
     {
         return  ships ;
     }

     /**
     *  @return  the currentShip
     */
     public   int  getCurrentShip ()  
     {
         return  currentShip ;
     }
        
     public   class   BoardListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )  
         {
             if (  e . getSource ()   instanceof   JButton )  
             {                
                 JButton  button  =   ( JButton ) e . getSource ();
                 int  rowClick  =   ( int ) button . getClientProperty ( "row" );
                 int  colClick  =   ( int ) button . getClientProperty ( "col" );
                
                 if (   ! isValid ( rowClick ,  colClick )   )
                 {
                     JOptionPane . showMessageDialog ( null ,   "Ship will not fit in selected location, select a different location" ,  
                             "Try again" ,   JOptionPane . ERROR_MESSAGE );
                 }     
                 else   if   ( isOccupied ( rowClick ,  colClick ))
                 {
                     JOptionPane . showMessageDialog ( null ,   "One or more spaces are occupied, select again" ,  
                             "Try again" ,   JOptionPane . ERROR_MESSAGE );
                 }
                 else
                 {
                    placeShip ( rowClick ,  colClick );
                 }
             }
         }
     }     
}

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/PlayerOptionDialog.java

BattleshipGame_Assignment2Solution/BattleshipGame/src/userInterface/PlayerOptionDialog.java

package  userInterface ;

import  core . Constants ;
import  java . awt . GridLayout ;
import  java . awt . BorderLayout ;
import  java . awt . Color ;
import  java . awt . Dimension ;

import  java . awt . event . ActionEvent ;
import  java . awt . event . ActionListener ;
import  java . util . Arrays ;
import  javax . swing . * ;
import  javax . swing . border . BevelBorder ;

/**
 *
 *  @author  kwhiting
 */
public   class   PlayerOptionDialog
{
     private   JDialog  dialog ;
     private   JPanel  playerOptionPanel ;
     private   JPanel  optionsPanel ;
     private   JPanel  buttonPanel ;
     private   JLabel  shipColorLbl ;  
     private   JLabel  firstPlayerLbl ;
     private   JComboBox  shipColor ;
     private   JComboBox  firstPlayer ;
     private   JButton  saveBtn ;
     private   JButton  canxBtn ;
     private   JRadioButton  player1 ;
     private   JRadioButton  player2 ;
     private   ButtonGroup  playerOptions ;
     private   static   Color []  color  =   { Color . CYAN ,   Color . GREEN ,   Color . MAGENTA ,   Color . ORANGE ,
                                     Color . PINK ,   Color . WHITE ,   Color . YELLOW };          

     private   static   String []  colors  =   { "Cyan" ,   "Green" ,   "Magenta" ,   "Magenta" ,  
                                       "Orange" ,   "Pink" ,   "White" ,   "Yellow" };
     private   static   String []  players  =   { "Player 1" ,   "Player 2" ,   "Random" };

     private   String  selectdColor ;
     private   String  selectedPlayer ;
  
     private   Player  currentPlayer ;
     private   Player []  playerArray ;
    
     public   PlayerOptionDialog ( JFrame  parent ,   Player []  inPlayers )
     {
        playerArray  =  inPlayers ;
        initComponents ( parent );
     }
    
     private   void  initComponents ( JFrame  parent )
     {
         // Dialog
        dialog  =   new   JDialog ( parent ,   true );
        dialog . setDefaultCloseOperation ( JDialog . DISPOSE_ON_CLOSE );
        
         // Options panels
        optionsPanel  =   new   JPanel ();
        optionsPanel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
        playerOptionPanel  =   new   JPanel ( new   GridLayout ( 3 ,   2 ));
        playerOptionPanel . setBorder ( BorderFactory . createTitledBorder ( "Player Options" ));
        playerOptionPanel . setPreferredSize ( new   Dimension ( 275 ,   125 ));
        
         // playerOptionPanel
        playerOptions  =   new   ButtonGroup ();
        player1  =   new   JRadioButton ( "Player 1" );
        player1 . addActionListener ( new   PlayerListener ());
        player2  =   new   JRadioButton ( "Player 2" );
        player2 . addActionListener ( new   PlayerListener ());
        playerOptions . add ( player1 );
        playerOptions . add ( player2 );
        playerOptionPanel . add ( player1 );
        playerOptionPanel . add ( player2 );
        
        shipColorLbl  =   new   JLabel ( "Ship Color" );
        playerOptionPanel . add ( shipColorLbl );                 
        shipColor  =   new   JComboBox ( colors );
        shipColor . setSelectedIndex ( 0 );   
        playerOptionPanel . add ( shipColor );

        firstPlayerLbl  =   new   JLabel ( "Who Plays First?" );
        playerOptionPanel . add ( firstPlayerLbl );
        firstPlayer  =   new   JComboBox ( players );
        firstPlayer . setSelectedIndex ( 0 );             
        playerOptionPanel . add ( firstPlayer );      

         // optionsPanel
        optionsPanel . add ( playerOptionPanel );
        
         // Button Panel
        saveBtn  =   new   JButton ( "Save" );
        saveBtn . addActionListener ( new   SaveListener ());       
        
        canxBtn  =   new   JButton ( "Cancel" );
        canxBtn . addActionListener ( new   CancelListener ());         
        
        buttonPanel  =   new   JPanel ();
        buttonPanel . setBorder ( BorderFactory . createBevelBorder ( BevelBorder . RAISED ));
        buttonPanel . add ( saveBtn );
        buttonPanel . add ( canxBtn );
        
         // Final setup
        dialog . setTitle ( "Options" );
        dialog . setLayout ( new   BorderLayout ());         
        dialog . getContentPane (). add ( optionsPanel ,   BorderLayout . CENTER );
        dialog . getContentPane (). add ( buttonPanel ,   BorderLayout . SOUTH );
        dialog . setMinimumSize ( new   Dimension ( 300 ,   225 ));
        dialog . setLocation ( 200 , 200 );
        dialog . setVisible ( true );         
     }
    
     private   void  initObjects ()
     {
        currentPlayer  =   new   Player ();
     }
    
     private   class   PlayerListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
             if ( player1 . isSelected ())
             {
                 int  colorIndex  =   Arrays . asList ( color ). indexOf ( playerArray [ Constants . PLAYER_ONE ]. getShipColor ());
                shipColor . setSelectedIndex ( colorIndex );
                
                 if ( playerArray [ Constants . PLAYER_ONE ]. isIsFirst ())
                    firstPlayer . setSelectedIndex ( Constants . PLAYER_ONE );
                 else
                    firstPlayer . setSelectedIndex ( Constants . PLAYER_TWO );
                
                currentPlayer  =  playerArray [ Constants . PLAYER_ONE ];
             }
             else   if ( player2 . isSelected ())
             {
                 int  colorIndex  =   Arrays . asList ( color ). indexOf ( playerArray [ Constants . PLAYER_TWO ]. getShipColor ());
                shipColor . setSelectedIndex ( colorIndex );
                
                 if ( playerArray [ Constants . PLAYER_TWO ]. isIsFirst ())
                    firstPlayer . setSelectedIndex ( Constants . PLAYER_TWO );
                 else
                    firstPlayer . setSelectedIndex ( Constants . PLAYER_ONE );

                currentPlayer  =  playerArray [ Constants . PLAYER_TWO ];
             }
         }             
     }    

     private   class   SaveListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
             if ( player1 . isSelected ())
             {
                playerArray [ Constants . PLAYER_ONE ]. setShipColor ( color [ shipColor . getSelectedIndex ()]);
                 boolean  isFirst  =  firstPlayer . getSelectedIndex ()   ==   0   ?   true   :   false ;
                playerArray [ Constants . PLAYER_ONE ]. setIsFirst ( isFirst );
                playerArray [ Constants . PLAYER_TWO ]. setIsFirst ( ! isFirst );
             }
             else   if ( player2 . isSelected ())
             {
                playerArray [ Constants . PLAYER_TWO ]. setShipColor ( color [ shipColor . getSelectedIndex ()]);
                 boolean  isFirst  =  firstPlayer . getSelectedIndex ()   ==   0   ?   true   :   false ;
                playerArray [ Constants . PLAYER_TWO ]. setIsFirst ( isFirst );
                playerArray [ Constants . PLAYER_ONE ]. setIsFirst ( ! isFirst );
             }                 
            
            dialog . dispose ();
         }             
     }    

     private   class   CancelListener   implements   ActionListener
     {    
         public   void  actionPerformed ( ActionEvent  e )
         {
            dialog . dispose ();
         }    
     }    
}