sto lavorando con netbeans. il codice è incompleto, xkè oltre alla scacchiera sto aggiungendo informazioni riguardo alla partita da visualizzare. Posto la parte relativa alla scacchiera.
codice:
import java.awt.Component;
import javax.swing.*;
import java.awt.*;
class Square extends JPanel {
private static final Color white = new Color(15787904);
private static final Color black = new Color(4333838);
public Square(boolean even) {
super();
this.setBackground(even ? white : black);
}
}
public class ChessBoard extends JFrame {
/** Creates a new instance of ChessBoard */
public ChessBoard() {
super("Simplest Chessboard Ever");
this.setLayout(new BorderLayout());
JPanel center = new JPanel();
center.setLayout(new GridLayout(8,8));
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
Component add = center.add(new Square((i+j)%2==0));
}
}
this.add(center, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setVisible(true);
}
public static void main (String[] args) {
new ChessBoard();
}
}