I am new to Java and I want to make a simple game of chess perhaps later will add sockets. First I wanted to start designing the board to which use GridLayout
JLabel
as shown . My problem is that I want to add to each Label an image to simulate the " chip " of the game but do not know how, I tried many things but does not leave me, I want help please.
This code generated my table of 8x8
public class Ventana extends javax.swing.JFrame {
private static final int COLUMNAS = 8;
private static final int FILAS = 8;
public Ventana() {
initComponents();
ImageIcon fNegra = new ImageIcon("Images/FichaNegra.png");
ImageIcon fRoja = new ImageIcon("Images/FichaRoja.png");
jPanel1.setLayout(new GridLayout(FILAS, COLUMNAS));
JLabel [][] jLabel = new JLabel[FILAS][COLUMNAS];
for (int i=0;i<FILAS;i++)
for (int j=0;j<COLUMNAS;j++)
{
jLabel[i][j] = new JLabel();
jLabel[i][j].setOpaque(true);
if((i+j)%2 == 0)
{
jLabel[i][j].setBackground(Color.WHITE);
jPanel1.add(jLabel[i][j]);
}
else
{
jLabel[i][j].setBackground(Color.GRAY);
jPanel1.add(jLabel[i][j]);
}
}
this.add(jPanel1);
this.setVisible(true);
}