I am working on a java tic tac toe game. First, I created a class for buttons, I then tried to store an array of instances of that class. Everything was working fine until I added those objects to the frame. Here is my code:
package tictactoe;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TicTacToe extends JFrame
{
TicTacToe()
{
this.setLayout(null);
this.setResizable(true);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setBackground(Color.blue);
PlayingButton[] b = new PlayingButton [9];
for (int i = 0 ; i < 9 ; i++)
{
b[i] = new PlayingButton();
}
b[0].setBounds(0,0,50,50);
b[1].setBounds(50,0,50,50);
b[2].setBounds(100,0,50,50);
this.add(b[0]);
this.setVisible(true);
}
public static void main(String[] args)
{
TicTacToe board = new TicTacToe();
}
}
The line that is causing me problems:
this.add(b[0]);
PlayingButton? What happened? Is there a stack trace? How do I ask a good question?