Battleship Java Program
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
);