|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
pictionary.pictionaryclient.PictionaryClientGUI
public class PictionaryClientGUI
A simple Pictionary GUI.
This class receives and forwards information to a PictionaryClient
Nested Class Summary | |
---|---|
private class |
PictionaryClientGUI.CloseWindowListener
A custom class used for overriding the default behaviour when the window is closed. |
private class |
PictionaryClientGUI.ConnectButtonListener
Custom listener class for handling the event that the user uses disconnectOrConnectBtn |
private class |
PictionaryClientGUI.JoinGameButtonListener
Handles the event that is generated when joinGameBtn is clicked. |
private class |
PictionaryClientGUI.Paper
A simple class for rendering a set of points. |
private class |
PictionaryClientGUI.SendButtonListener
Handles the event that is generated when the user clicks sendTextBtn |
Nested classes/interfaces inherited from class javax.swing.JFrame |
---|
javax.swing.JFrame.AccessibleJFrame |
Nested classes/interfaces inherited from class java.awt.Frame |
---|
java.awt.Frame.AccessibleAWTFrame |
Nested classes/interfaces inherited from class java.awt.Window |
---|
java.awt.Window.AccessibleAWTWindow |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
private PictionaryClient |
client
The PictionaryClient that we receive and forward events from/to. |
private boolean |
connected
True if the client is connected to the server, else false. |
private javax.swing.JButton |
disconnectOrConnectBtn
The button used for connecting and disconnecting to/from the server, is initially used for connecting. |
private javax.swing.JTextField |
guessField
The field where the user inputs guesses when playing a game of pictionary. |
private javax.swing.JTextArea |
inputArea
The area where chat text is input. |
private javax.swing.JScrollPane |
inputAreaScrollPane
The JScrollPane that inputArea is attached to. |
private javax.swing.JButton |
joinGameBtn
The button used when joining or disconnecting from a game. |
private PictionaryClientGUI.Paper |
paper
The PictionaryClientGUI.Paper on which the user can draw and also see what other players are drawing. |
private javax.swing.JTextArea |
receivedText
The text area that contains received messages from the server and other clients. |
private javax.swing.JScrollPane |
receivedTextScrollPane
The JScrollPane that receivedText is attached to. |
private javax.swing.JButton |
sendTextBtn
A button that can be used for sending the text in inputArea . |
Fields inherited from class javax.swing.JFrame |
---|
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled |
Fields inherited from class java.awt.Frame |
---|
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.WindowConstants |
---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
PictionaryClientGUI(PictionaryClient client)
The constructor. |
Method Summary | |
---|---|
void |
aClientConnected(java.lang.String client)
This method is called when a new client has connected to the server. |
void |
aClientDisconnected(java.lang.String client)
This method is called when a client has disconnected from the server. |
private void |
broadCastText()
Sends the text in inputArea to the server
using PictionaryClient.broadcastChatMessage(String) . |
void |
clientBroadcastMessageReceived(java.lang.String client,
java.lang.String message)
This method is called when a message from a client, broadcasted to all other clients, is received. |
void |
clientStartedDrawing(java.lang.String client)
This method is called when a client has started drawing. |
void |
closedByError(java.lang.String error)
This method is called when the connection to the server has been closed. |
void |
connectedToServer()
This method is called when the player successfully connected to a server. |
void |
correctGuess()
This method is called when the player has made a correct guess. |
void |
correctGuessBroadcastReceived(java.lang.String player,
java.lang.String guess)
This method is called to notify the client that a player made a correct guess. |
private void |
disconnect()
Disconnects from the server. |
void |
drawReceived(java.awt.Point point)
This method is called to notify the client that the drawing player drew at a specific point. |
private void |
guess(java.lang.String guess)
Used when the client wants to guess on a word while in a game of Pictionary. |
void |
joinedNewGame(java.util.List<java.lang.String> players,
int gameStatus)
This method is called when the client successfully joined a game of Pictionary. |
static void |
main(java.lang.String[] args)
Asks the user for hostname and port, and then creates an instance of #PictionaryClient
using these values. |
private void |
onServerDisconnect()
Called when the connection to the server is lost. |
void |
serverDisconnected()
This method is called when the connection to the server is lost. |
void |
serverMessageReceived(java.lang.String message)
This method is called when a message from the server sent to all the clients is received. |
void |
startDrawing(java.lang.String wordToDraw,
int drawTime)
This method is called when the player should start drawing a word. |
void |
startGuessing()
This method is called to notify the client that a player is drawing and that the client can start making guesses. |
void |
stopDrawing()
This method is called to notify the client that it should stop drawing. |
void |
stopGuessing()
This method is called to notify the client that it should stop guessing, for example when someone made a correct guess or when the drawing player's time is up. |
java.lang.String |
userNameRequest()
This method is called when the server has requested the client to respond with an username. |
void |
wrongGuessBroadcastReceived(java.lang.String player,
java.lang.String guess)
This method notifies the client that a player made an incorrect guess. |
Methods inherited from class javax.swing.JFrame |
---|
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update |
Methods inherited from class java.awt.Frame |
---|
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated |
Methods inherited from class java.awt.Window |
---|
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
---|
getFont, postEvent |
Field Detail |
---|
private PictionaryClient client
PictionaryClient
that we receive and forward events from/to.
private javax.swing.JTextArea receivedText
private javax.swing.JTextArea inputArea
private javax.swing.JScrollPane receivedTextScrollPane
receivedText
is attached to.
private javax.swing.JScrollPane inputAreaScrollPane
inputArea
is attached to.
private javax.swing.JButton disconnectOrConnectBtn
private boolean connected
private javax.swing.JButton joinGameBtn
private javax.swing.JButton sendTextBtn
inputArea
.
private javax.swing.JTextField guessField
private PictionaryClientGUI.Paper paper
PictionaryClientGUI.Paper
on which the user can draw and also see what other players are drawing.
Constructor Detail |
---|
public PictionaryClientGUI(PictionaryClient client)
client
- The PictionaryClient
, see client
.Method Detail |
---|
private void onServerDisconnect()
private void disconnect()
private void broadCastText()
inputArea
to the server
using PictionaryClient.broadcastChatMessage(String)
.
private void guess(java.lang.String guess)
guess
- The word that is the client's guess.public void correctGuessBroadcastReceived(java.lang.String player, java.lang.String guess)
IPictionaryClientCallback
correctGuessBroadcastReceived
in interface IPictionaryClientCallback
player
- The name of the player that made the correct guess.guess
- The guess that was made.public void correctGuess()
IPictionaryClientCallback
correctGuess
in interface IPictionaryClientCallback
public void wrongGuessBroadcastReceived(java.lang.String player, java.lang.String guess)
IPictionaryClientCallback
wrongGuessBroadcastReceived
in interface IPictionaryClientCallback
player
- The name of the player that made the incorrect guess.guess
- The incorrect guess.public void aClientDisconnected(java.lang.String client)
IPictionaryClientCallback
aClientDisconnected
in interface IPictionaryClientCallback
client
- The name of the client that disconnected.public void aClientConnected(java.lang.String client)
IPictionaryClientCallback
aClientConnected
in interface IPictionaryClientCallback
client
- The name of the new client that connected.public void serverMessageReceived(java.lang.String message)
IPictionaryClientCallback
serverMessageReceived
in interface IPictionaryClientCallback
message
- The Message
sent from the server.public void clientBroadcastMessageReceived(java.lang.String client, java.lang.String message)
IPictionaryClientCallback
clientBroadcastMessageReceived
in interface IPictionaryClientCallback
client
- The name of the client that sent the message.message
- The Message
sent from
public void connectedToServer()
IPictionaryClientCallback
connectedToServer
in interface IPictionaryClientCallback
public void joinedNewGame(java.util.List<java.lang.String> players, int gameStatus)
IPictionaryClientCallback
joinedNewGame
in interface IPictionaryClientCallback
players
- All the players participating in the game.gameStatus
- The status of the game, equal to a status int in PictionaryGame
.public void startDrawing(java.lang.String wordToDraw, int drawTime)
IPictionaryClientCallback
startDrawing
in interface IPictionaryClientCallback
wordToDraw
- The word that the player should attempt to draw.drawTime
- The amount of time, in seconds, the player can draw before his time is up.public void drawReceived(java.awt.Point point)
IPictionaryClientCallback
drawReceived
in interface IPictionaryClientCallback
point
- A Point
containing the coordinates that were filled.public void serverDisconnected()
IPictionaryClientCallback
serverDisconnected
in interface IPictionaryClientCallback
public void stopDrawing()
IPictionaryClientCallback
stopDrawing
in interface IPictionaryClientCallback
public void startGuessing()
IPictionaryClientCallback
startGuessing
in interface IPictionaryClientCallback
public void stopGuessing()
IPictionaryClientCallback
stopGuessing
in interface IPictionaryClientCallback
public java.lang.String userNameRequest()
IPictionaryClientCallback
userNameRequest
in interface IPictionaryClientCallback
public void clientStartedDrawing(java.lang.String client)
IPictionaryClientCallback
clientStartedDrawing
in interface IPictionaryClientCallback
client
- The name of the client that started drawing.public void closedByError(java.lang.String error)
IPictionaryClientCallback
closedByError
in interface IPictionaryClientCallback
error
- A description of the cause to the error.public static void main(java.lang.String[] args)
#PictionaryClient
using these values. Creates an instance of PictionaryClientGUI
,
passing the aforementioned client to its constructor.
args
- Not used, the values are entered in an GUI.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |