Changed updateBoard method in Gui to use DTOs

Quicksave
Justin 2025-06-19 20:20:03 +02:00
parent 3ee0a5ece8
commit 441d4a3343
1 changed files with 17 additions and 7 deletions

View File

@ -14,6 +14,9 @@ import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import de.hs_mannheim.informatik.chess.model.BoardDTO;
import de.hs_mannheim.informatik.chess.model.PieceDTO;
public class Gui {
private JLabel[][] fields = new JLabel[8][8];
@ -111,13 +114,20 @@ public class Gui {
return fields[row][col];
}
public void updateBoard(String[][] unicodeBoard) {
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
fields[row][col].setText(unicodeBoard[row][col]);
}
}
}
public void updateBoard(BoardDTO boardDTO) {
PieceDTO[][] board = boardDTO.getBoard();
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
PieceDTO piece = board[row][col];
if (piece != null) {
fields[row][col].setText(piece.getUnicodeSymbol());
} else {
fields[row][col].setText("");
}
}
}
}
public void displayMessage(String msg) {
JOptionPane.showMessageDialog(null, msg);