com.antelmann.game.chess
Interface ChessGraphics
- All Known Implementing Classes:
- SampleChessGraphics
public interface ChessGraphics
This interface allows other programs to customize the appearence
of the graphics used by the class JChess to visualize the chess board.
All methods expect one of constants of either WHITE or BLACK as
parameters; otherwise, an exception may be thrown.
The following conventions should be used to implement this interface
in a usable way:
- make all icons square shaped (width = height) to avoid streching
- the icons should have a transparent background (like GIF images), so that the tile background color can be seen through
- when deciding on a size for your icons, keep in mind your screen resolution and the size of a chess board (8x8)
- it is always the white king's icon that will determine standard display size for all icons
the default height/width used by SampleChessGraphics is 32 pixels
Here is some sample code that demonstrates how to potentially customize
only some graphics by simply overriding some methods of the ChessGraphics
implementing class SampleChessGraphics:
java.net.URL blackKingImageURL = ...;
java.net.URL whitePawnURL = ...;
java.net.URL blackPawnURL = ...;
JChess jchess = new JChess();
jchess.setGraphics(new SampleChessGraphics(1) {
public ImageIcon getKingIcon(int color) {
// customizing only the black king
if (color == ChessGraphics.WHITE)
return super.getKingIcon(ChessGraphics.WHITE);
else return new ImageIcon(blackKingImageURL);
}
public ImageIcon getPawnIcon(int color) {
switch (color) {
case ChessGraphics.WHITE: return new ImageIcon(whitePawnURL);
case ChessGraphics.BLACK: return new ImageIcon(blackPawnURL);
default: throw new IllegalArgumentException();
}
}
});
new JGameFrame(jchess).setVisible(true);
- Author:
- Holger Antelmann
- See Also:
SampleChessGraphics,
JChess.setGraphics(ChessGraphics)
WHITE
static final int WHITE
- See Also:
- Constant Field Values
BLACK
static final int BLACK
- See Also:
- Constant Field Values
getKingIcon
ImageIcon getKingIcon(int color)
getQueenIcon
ImageIcon getQueenIcon(int color)
getRookIcon
ImageIcon getRookIcon(int color)
getKnightIcon
ImageIcon getKnightIcon(int color)
getBishopIcon
ImageIcon getBishopIcon(int color)
getPawnIcon
ImageIcon getPawnIcon(int color)
(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads