Holger's
Java API

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:

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)

Field Summary
static int BLACK
           
static int WHITE
           
 
Method Summary
 ImageIcon getBishopIcon(int color)
           
 ImageIcon getKingIcon(int color)
           
 ImageIcon getKnightIcon(int color)
           
 ImageIcon getPawnIcon(int color)
           
 ImageIcon getQueenIcon(int color)
           
 ImageIcon getRookIcon(int color)
           
 

Field Detail

WHITE

static final int WHITE
See Also:
Constant Field Values

BLACK

static final int BLACK
See Also:
Constant Field Values
Method Detail

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