0

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]);
4
  • 3
    And then, what happens? What do you expect the code to do, and what does it do instead? Commented Dec 14, 2016 at 18:51
  • 1
    What is PlayingButton? What happened? Is there a stack trace? How do I ask a good question? Commented Dec 14, 2016 at 18:51
  • 1
    PlayingButton is another class i created it to take an objects from it . Commented Dec 14, 2016 at 18:53
  • 2
    @M-AmrMoussa Yes, but how are we supposed to find a problem with it if we can't see how it was coded? You need to provide a Minimal, Complete, and Verifiable example Commented Dec 14, 2016 at 18:54

1 Answer 1

3

PlayingButton class should extend JComponent or it's subclasses.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.