アプレットに表示する必要があるチェス プログラムを Java で作成しています。現在、チェスの駒の配列を埋めるのに問題があります。これは現在、JApplet の paint() メソッドで行われていますが、paint は複数回呼び出される可能性があるため、これが間違っていることはわかっています。配列を作成して初期化メソッドに入力しようとしましたが、まったく機能しません。どんな助けでも大歓迎です。
public class DrawChessBoard extends JApplet
implements MouseListener, MouseMotionListener {
ChessPiece myPiece;
ImageIcon square;
ImageObserver observer;
ChessBoard gameBoard;
boolean isMouseDragging = false;
int size; //square dimensions
public void initialize() {
setBackground(Color.white);
Image bSquare = square.getImage();
size = bSquare.getWidth(observer);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics h) {
Graphics2D g = (Graphics2D) h;
//System.out.println("Am I being called more than once?");
gameBoard = new ChessBoard(8);
gameBoard.start();
gameBoard.paintBoard(g);
gameBoard.paintComponent(g);
}
}