Import javax.swing. *;
Public chess extension JPanel
{//inherit the panel class.
The public chess (int grids, int gridsize)
{//grids: number of rows and columns, gridsize: height and width of cells.
Super (empty);
for(int I = 0; I < grid; i++)
{
for(int j = 0; J< grid; j++)
{
JLabel l = new JLabel(); //Generate a label instance
l.setSize(gridsize,gridsize);
l.setLocation(i*gridsize,j * gridsize);
If ((i+j)%2==0)
{//When the coordinate sum of small squares happens to be even,
l . set background(color . black); //Set the grid to black.
L.setOpaque (true); //set to opaque
}
l . set border(border factory . createlineborder(color . black)); //Set the border to black.
Add (l); //Add the L tag to the panel
}
}
}
Public static void main(String[] args)
{
JFrame f = new JFrame();
f.setSize(658,677); //The length and width of the border
f . setlocationrelativeto(null); //Sets the position of the window relative to the specified component.
F.add (xinqi (8,80));
f . set visible(true);
}
}