|
|||||||||
| Home >> All >> [ antichess overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
antichess
Class XChessBoard

java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLayeredPane
antichess.XChessBoard
- All Implemented Interfaces:
- javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable
- public class XChessBoard
- extends javax.swing.JLayeredPane
- implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener
- extends javax.swing.JLayeredPane
XChessBoard creates an antichess board image on the board, places pieces on it, and animates pieces for drag&drop.
Here is the outline of how XChessBoard handles an antichess board:
Everytime setGameController is called, a new backgroud image is created
by first calling initBoard() and then, setBoardImage().
placePieces() creates labels with piece images for every non-empty square. It places this accordingly on the board.
updateBoard() goes through all the squares of the board. It updates the positions of already created pieces. If there are not enough labels, it creates new labels. If there are any excess labels it gets rid of them.
Drag&drop is implemented through JLabel.setLocation() method. This provides a flawless animation compared to other methods.
| Nested Class Summary |
| Nested classes inherited from class javax.swing.JLayeredPane |
javax.swing.JLayeredPane.AccessibleJLayeredPane |
| Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
private int |
arbX
|
private int |
arbY
|
private javax.swing.JLabel |
background
|
private java.awt.Color |
BLACKCOLOR
|
private Board |
board
|
private int |
boardMargin
|
private javax.swing.JLabel[][] |
circArray
|
private javax.swing.JLabel[][] |
circArray2
|
private static boolean |
DEBUG
|
private int |
endCol
|
private int |
endRow
|
private int |
fourtwoMargin
|
private static GameController |
gc
|
private HumanPlayer |
human
|
private java.util.ArrayList[] |
labelList
|
private int |
letterMargin
|
private boolean |
mousePress
|
private javax.swing.JLabel |
movingLabel
|
private java.awt.Image[] |
pieceImageList
|
private int |
piecePaddingX
|
private int |
piecePaddingY
|
private int |
pieceSizeX
|
private int |
pieceSizeY
|
private int |
SIZEX
|
private int |
SIZEY
|
private int |
squareSizeX
|
private int |
squareSizeY
|
private int |
startCol
|
private char |
startLetter
|
private char |
startNumber
|
private int |
startRow
|
private java.awt.Color |
WHITECOLOR
|
| Fields inherited from class javax.swing.JLayeredPane |
DEFAULT_LAYER, DRAG_LAYER, FRAME_CONTENT_LAYER, LAYER_PROPERTY, MODAL_LAYER, PALETTE_LAYER, POPUP_LAYER |
| 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.Container |
|
| 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 | |
XChessBoard()
Creates new form XChessBoard |
|
| Method Summary | |
private void |
getCircles()
Loads the red circle images from the directory that indicate valid pieces to be moved |
private void |
getCircles2()
Loads the blue circle images from the directory that indicate valid moves that can be made by piece being moved |
private void |
getImages()
Loads the images from the directory |
private void |
initBoard()
Initalizes the board variables |
private void |
initComponents()
This method is called from within the constructor to initialize the form. |
private void |
initValues()
Initializes global variables |
void |
mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component. |
void |
mouseDragged(java.awt.event.MouseEvent e)
Invoked when a mouse button is pressed on a component and then dragged. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component. |
void |
mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component. |
void |
mouseMoved(java.awt.event.MouseEvent e)
Invoked when the mouse button has been moved on a component (with no buttons down). |
void |
mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component. |
private void |
placeCircles()
Method to place red circles on the board that indicate the pieces that can be moved |
private void |
placeCircles2()
|
private void |
placePieces()
Method to place pieces on the board |
private void |
setBoardImage()
Sets the board image for background. |
void |
setGameController(GameController gc)
Sets the GameController handler to the specified gamecontroller |
void |
updateBoard()
Method to update pieces on the board Goes through board, and if there is a piece at (i,j) takes a label from labelList, puts the necessary image on it places it on the right place. |
| Methods inherited from class javax.swing.JLayeredPane |
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentsInLayer, getComponentToLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, putLayer, remove, removeAll, setLayer, setLayer, setPosition |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
gc
private static GameController gc
board
private Board board
SIZEX
private int SIZEX
SIZEY
private int SIZEY
letterMargin
private int letterMargin
squareSizeX
private int squareSizeX
squareSizeY
private int squareSizeY
pieceSizeX
private int pieceSizeX
pieceSizeY
private int pieceSizeY
startLetter
private char startLetter
startNumber
private char startNumber
WHITECOLOR
private java.awt.Color WHITECOLOR
BLACKCOLOR
private java.awt.Color BLACKCOLOR
boardMargin
private int boardMargin
fourtwoMargin
private int fourtwoMargin
pieceImageList
private java.awt.Image[] pieceImageList
piecePaddingX
private int piecePaddingX
piecePaddingY
private int piecePaddingY
startCol
private int startCol
startRow
private int startRow
endCol
private int endCol
endRow
private int endRow
background
private javax.swing.JLabel background
labelList
private java.util.ArrayList[] labelList
movingLabel
private javax.swing.JLabel movingLabel
arbX
private int arbX
arbY
private int arbY
mousePress
private boolean mousePress
circArray
private javax.swing.JLabel[][] circArray
circArray2
private javax.swing.JLabel[][] circArray2
human
private HumanPlayer human
| Constructor Detail |
XChessBoard
public XChessBoard()
- Creates new form XChessBoard
| Method Detail |
initComponents
private void initComponents()
- This method is called from within the constructor to
initialize the form.
initValues
private void initValues()
- Initializes global variables
getImages
private void getImages()
- Loads the images from the directory
getCircles
private void getCircles()
- Loads the red circle images from the directory that indicate valid pieces to be moved
getCircles2
private void getCircles2()
- Loads the blue circle images from the directory that indicate valid moves that can be made by piece being moved
placeCircles
private void placeCircles()
- Method to place red circles on the board that indicate the pieces that can be moved
placeCircles2
private void placeCircles2()
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Invoked when the mouse button has been clicked (pressed
and released) on a component.
- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Invoked when the mouse enters a component.
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Invoked when the mouse exits a component.
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Invoked when the mouse button has been moved on a component (with no buttons down).
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Invoked when a mouse button is pressed on a component and then
dragged.
MOUSE_DRAGGEDevents will continue to be delivered to the component where the drag originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the component).Due to platform-dependent Drag&Drop implementations,
MOUSE_DRAGGEDevents may not be delivered during a native Drag&Drop operation.- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Invoked when a mouse button has been pressed on a component.
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Invoked when a mouse button has been released on a component.
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
setGameController
public void setGameController(GameController gc)
- Sets the GameController handler to the specified gamecontroller
initBoard
private void initBoard()
- Initalizes the board variables
setBoardImage
private void setBoardImage()
- Sets the board image for background.
Paints squares in given BLACKCOLOR and WHITECOLOR.
Adds position letters/numbers at the bottom and on
the right
placePieces
private void placePieces()
- Method to place pieces on the board
updateBoard
public void updateBoard()
- Method to update pieces on the board
Goes through board, and if there is a piece at (i,j)
takes a label from labelList, puts the necessary image on it
places it on the right place.
This method discards labels if there are less pieces on the board.
|
|||||||||
| Home >> All >> [ antichess overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC