Here's the code:
class SingleBoard extends JPanel
{
public SingleBoard (ActionListener e)
{
setLayout (new GridLayout (3, 3));
for (int i = 0 ; i <= 8 ; i++)
{
buttons [i] = new JButton ();
buttons [i].addActionListener (e);
add (buttons [i]);
}
}
}
public void init ()
{
setSize (300, 700);
JLabel message = new JLabel ("X will go first");
getContentPane ().setLayout (new BorderLayout ());
getContentPane ().add (message, BorderLayout.NORTH);
getContentPane ().setLayout (new GridLayout (5, 5, 10, 10));
for (int i = 0 ; i < 3 ; i++)
{
SingleBoard sb = new SingleBoard (this);
getContentPane ().add (sb);
}
}
My only problem is that the last panel is the only one I think retains the variable names buttons[0]-buttons[8], so I'm having problem to check the winner. I don't know how to access/reference the buttons on the first 2 panels