|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
TTTpanel
public class TTTpanel
Actual GUI part of the engine. Handles mouse clicks, checks for a winner, and draws the board.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
javax.swing.JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| 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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
private java.lang.String[] |
board
string array representation of the TTT board |
private static LearningAlgorithm |
curOpponent
the current opponent |
private static java.lang.String |
instigator
the CCP ID of the module that started the auto mode game |
private javax.swing.JLabel |
lblMessage
the message to be displayed on the GUI |
private static java.lang.String |
player1
the first player: "HUMAN" or "ROBOT" |
private static boolean |
playerX
TRUE for X's turn, FALSE for O's turn |
private static boolean |
playing
TRUE if game is currently being played, FALSE if no game |
private static boolean |
tie
TRUE if game is a tie, FALSE if no tie |
private TTTengine |
tttEngine
reference to the main engine class |
private static boolean |
win
TRUE if someone has won, FALSE if no one has won |
private static int[][] |
winIndex
all the possible winning combinations |
private static java.awt.geom.Line2D |
winLine
line representing the winning TTT moves |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
TTTpanel(TTTengine tttEngine)
Constructs a new tic tac toe board, accepts a reference to the CCP client, and sets it to X's turn |
|
| Method Summary | |
|---|---|
void |
drawO(java.awt.Graphics2D g2,
int i)
Draws an O on the board in a given cell(1-9) |
void |
drawX(java.awt.Graphics2D g2,
int i)
Draws an X on the board in a given cell(1-9) |
java.lang.String[] |
getBoard()
Return an array of strings representing the tic tac toe board |
LearningAlgorithm |
getCurAlgorithm()
Get current opponent |
java.lang.String |
getInstigator()
Get the name of the instigator |
java.lang.String |
getOtherPlayer(java.lang.String player)
Find name of the other player given a player |
java.lang.String |
getPlayer1()
Return the first player |
boolean |
getPlayerX()
Gets whose turn it is(X's or O's turn) |
boolean |
isAWin()
Sees if someone has one yet |
boolean |
isEmpty(int i)
Checks if the current cell is empty |
boolean |
isHumanTurn()
Find out if it is the Human's turn |
boolean |
isPlaying()
See if game is currently going on |
void |
mouseClicked(java.awt.event.MouseEvent event)
Invoked when the mouse is clicked, draws an X or O in the cell that was clicked on |
void |
mouseEntered(java.awt.event.MouseEvent arg0)
Method that has to be implemented but is not necessary |
void |
mouseExited(java.awt.event.MouseEvent arg0)
Method that has to be implemented but is not necessary |
void |
mousePressed(java.awt.event.MouseEvent arg0)
Method that has to be implemented but is not necessary |
void |
mouseReleased(java.awt.event.MouseEvent arg0)
Method that has to be implemented but is not necessary |
void |
paintComponent(java.awt.Graphics page)
Draws the tic tac toe board and moves |
void |
setBoard(int i,
java.lang.String letter)
Set cell i equal to the given letter. |
void |
setCurAlgorithm(LearningAlgorithm opponent)
Set the current opponent |
void |
setInstigator(java.lang.String instigator)
Set new game instigator |
void |
setMessage(java.lang.String message)
Sets the GUI message |
void |
setPlayer1(java.lang.String player1)
Set the first player |
void |
setPlayerX(boolean playerX)
Sets whose turn it is |
void |
setPlaying(boolean playing)
Sets if game is going on or not |
void |
setupNewGame(java.lang.String player1)
Various assignments to start a new game |
void |
setWin(boolean win)
Sets a win flag so win line will show |
void |
swapPlayer()
Switches to next player's turn |
java.lang.String |
whoWon(int lastMove)
Checks to find a human win, robot win, or tie |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private java.lang.String[] board
private TTTengine tttEngine
private static java.awt.geom.Line2D winLine
private static java.lang.String player1
private static java.lang.String instigator
private static boolean playerX
private static boolean playing
private static boolean win
private static boolean tie
private static LearningAlgorithm curOpponent
private javax.swing.JLabel lblMessage
private static final int[][] winIndex
| Constructor Detail |
|---|
public TTTpanel(TTTengine tttEngine)
| Method Detail |
|---|
public void paintComponent(java.awt.Graphics page)
paintComponent in class javax.swing.JComponentpage - - The graphics object for painting the board
public void drawX(java.awt.Graphics2D g2,
int i)
g2 - - The graphics object for painting the boardi - - The number of the cell(1-9)
public void drawO(java.awt.Graphics2D g2,
int i)
g2 - - The graphics object for painting the boardi - - The number of the cell(1-9)public boolean isEmpty(int i)
i - - The cell number to be checked
public java.lang.String whoWon(int lastMove)
lastMove - - last move that filled the TTT board
public java.lang.String[] getBoard()
public void setBoard(int i,
java.lang.String letter)
i - - square to be setletter - - letter to set square topublic void setupNewGame(java.lang.String player1)
player1 - - the starting player: "HUMAN" or "ROBOT"public boolean getPlayerX()
public void setPlayerX(boolean playerX)
playerX - - Set True for X's turn, False for O's turnpublic java.lang.String getOtherPlayer(java.lang.String player)
player - - name of player to find the other one of
public java.lang.String getPlayer1()
public void setPlayer1(java.lang.String player1)
player1 - - name of first playerpublic void setPlaying(boolean playing)
playing - - True for playing game, False for not
playing a gamepublic boolean isPlaying()
public void setMessage(java.lang.String message)
message - - message to be displayed on the GUIpublic void setWin(boolean win)
win - - TRUE if someone won, FALSE if no one wonpublic boolean isAWin()
public void setCurAlgorithm(LearningAlgorithm opponent)
opponent - - New opponent to be setpublic LearningAlgorithm getCurAlgorithm()
public void swapPlayer()
public void setInstigator(java.lang.String instigator)
instigator - - CCP ID of instigatorpublic java.lang.String getInstigator()
public boolean isHumanTurn()
public void mouseClicked(java.awt.event.MouseEvent event)
mouseClicked in interface java.awt.event.MouseListenerevent - - Information about the mouse clickpublic void mousePressed(java.awt.event.MouseEvent arg0)
mousePressed in interface java.awt.event.MouseListenerpublic void mouseReleased(java.awt.event.MouseEvent arg0)
mouseReleased in interface java.awt.event.MouseListenerpublic void mouseEntered(java.awt.event.MouseEvent arg0)
mouseEntered in interface java.awt.event.MouseListenerpublic void mouseExited(java.awt.event.MouseEvent arg0)
mouseExited in interface java.awt.event.MouseListener
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||