Package battleship.view
Class Window
java.lang.Object
battleship.view.AbstractView
battleship.view.Window
- All Implemented Interfaces:
View
public class Window extends AbstractView
Window view, instanced if argument 2 equals to "nogui"
- See Also:
View
,AbstractView
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Window.Draw
Panel where we paint the board -
Field Summary
Fields Modifier and Type Field Description (package private) javax.swing.JFrame
frame
int
height
grids height, do no represent frame sizeprivate WindowKeyboardListener
keyboardComponent
private WindowMouseListener
mouseComponent
(package private) java.lang.String
upperSubTitle
(package private) java.lang.String
upperTitle
int
width
grids width, do no represent frame sizeFields inherited from class battleship.view.AbstractView
game
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Pair<java.lang.Integer,java.lang.Integer>
chooseMove(Player player)
ask player to choose a position in its opponent gridvoid
displayBoard()
refresh windows to display updated contentvoid
displayWinner(Player winner)
open a dialog to display the winner and exit the program when window is closedprotected java.lang.String
getKeyInput()
ask player for keyboard input and return resultprotected java.lang.String
keyboardInput()
askGame.currentPlayer
for keyboard inputprotected Pair<java.lang.Integer,java.lang.Integer>
mouseInput(Player player)
askplayer
for mouse inputvoid
openDialog(java.lang.String message)
Open a window withmessage
as content and with a "OK" buttonvoid
openDialog(java.lang.String message, boolean exitOnClose)
Open a window withmessage
as content and with a "OK" buttonvoid
setShips(Player player)
Askplayer
to set position of its shipsprotected void
setUpperText(java.lang.String s)
Display a text above the gridMethods inherited from class battleship.view.AbstractView
getDirectionFromChar, toString, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
frame
final javax.swing.JFrame frame -
height
public final int heightgrids height, do no represent frame size- See Also:
- Constant Field Values
-
width
public final int widthgrids width, do no represent frame size- See Also:
- Constant Field Values
-
mouseComponent
-
keyboardComponent
-
upperTitle
java.lang.String upperTitle -
upperSubTitle
java.lang.String upperSubTitle
-
-
Constructor Details
-
Window
-
-
Method Details
-
getKeyInput
protected java.lang.String getKeyInput() throws java.lang.InterruptedExceptionDescription copied from class:AbstractView
ask player for keyboard input and return result- Specified by:
getKeyInput
in classAbstractView
- Returns:
- String given by player
- Throws:
java.lang.InterruptedException
- seegetKeyInput()
-
setUpperText
protected void setUpperText(java.lang.String s)Display a text above the grid- Specified by:
setUpperText
in classAbstractView
- Parameters:
s
- text to display- See Also:
setUpperText(String)
,Terminal.setUpperText(String)
-
setShips
Askplayer
to set position of its ships- Specified by:
setShips
in interfaceView
- Overrides:
setShips
in classAbstractView
- Parameters:
player
- player we ask- Throws:
java.lang.InterruptedException
- seemouseInput(Player)
andAbstractView.getDirectionFromChar()
-
keyboardInput
protected java.lang.String keyboardInput() throws java.lang.InterruptedExceptionaskGame.currentPlayer
for keyboard input- Specified by:
keyboardInput
in classAbstractView
- Returns:
- String given by player
- Throws:
java.lang.InterruptedException
- throw if this Thread is interrupted whilesleeping
- See Also:
keyboardInput()
,Terminal.keyboardInput()
,Terminal.keyboardInputInteger()
-
mouseInput
protected Pair<java.lang.Integer,java.lang.Integer> mouseInput(Player player) throws java.lang.InterruptedExceptionaskplayer
for mouse input- Specified by:
mouseInput
in classAbstractView
- Parameters:
player
-Game.currentPlayer
- Returns:
- coordinate of
player
opponent grid - Throws:
java.lang.InterruptedException
- throw if this Thread is interrupted whilesleeping
- See Also:
mouseInput(Player)
-
openDialog
public void openDialog(java.lang.String message, boolean exitOnClose)Open a window withmessage
as content and with a "OK" button- Parameters:
message
- message to displayexitOnClose
-true
if when user close this window, the program exit,false
otherwise
-
openDialog
public void openDialog(java.lang.String message)Open a window withmessage
as content and with a "OK" button- Parameters:
message
- message to display- See Also:
openDialog(String, boolean)
-
displayBoard
public void displayBoard()refresh windows to display updated content -
chooseMove
public Pair<java.lang.Integer,java.lang.Integer> chooseMove(Player player) throws java.lang.InterruptedExceptionask player to choose a position in its opponent grid- Specified by:
chooseMove
in interfaceView
- Overrides:
chooseMove
in classAbstractView
- Parameters:
player
-Game.currentPlayer
- Returns:
- a couple (
Pair
containing the x and y coordinate (left side store Y and right side X) - Throws:
java.lang.InterruptedException
- seemouseInput(Player)
-
displayWinner
open a dialog to display the winner and exit the program when window is closed- Parameters:
winner
- the winner of the game.- See Also:
displayWinner(Player)
,Terminal.displayWinner(Player)
-