How to make a 6 x 6 board using the swing library, in netbeans, and with what elements is the best way to do it?

1

I have this project for my programming class 1 for which I must play a board game, and I do not know how to make the board, I would like to help me how to do it using the pallete, thank you very much for answering me .

    
asked by Damaso Fernandez 27.02.2017 в 03:24
source

1 answer

1

Use a GridLayout (Grid distribution), and in each cell add a JPanel to which you can put a background color and border if you need to distinguish some cells from others.

Here is a bit of code:

///Define el tamaño de la cuadricula. 

Nombre_De_Tu_Frame.setLayout(new GridLayout(6,6));

///for para agregar paneles.
for(int i=0;i<6*6;i++){
JPanel panel=new JPanel();
panel.setBackground(Color.red);  ///se asigna un color.
Border borde;
borde = BorderFactory.createLineBorder(Color.black);  ///se le pone un borde.
panel.setBorder(borde);
Nombre_De_Tu_Frame.add(panel); ///Se agrega el panel a la cuadricula una vez que tiene color y borde.
}
    
answered by 27.02.2017 в 04:00