애플릿에 표시되어야하는 Java로 체스 프로그램을 작성하고 있습니다. 현재 체스 조각을 채우는 데 문제가 있습니다. 이것은 현재 내 JApplet의 paint() 메소드에서 수행되고 있으며 페인트가 두 번 이상 호출 될 수 있기 때문에 잘못되었다는 것을 알고 있습니다. 내가 배열을 작성하고 그것을 초기화하는 방법을 작성했지만 시도가 전혀 작동하지 않습니다. 어떤 도움을 주시면 감사하겠습니다.Java Chess Applet
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);
}
}
[예] (http://stackoverflow.com/questions/2561690/placing-component-on-glass-pane/2562685#2562685) 및 [유사 콘텐츠] (http://stackoverflow.com/questions/)를 참조하십시오. 2561690/유리 위에 놓는 구성 요소/2563350 # 2563350). – trashgod
"전혀 작동하지 않습니다"를 정의 하시겠습니까? 적어도 초기화 작업을 시작하기 위해 초기화 할 위치를 정확히 생각할 것입니다. (예를 들어, 새 게임을 시작할 때 초기화 할 수도 있습니다.) –