Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在数组中存储对象并显示它们(Java)_Java_Oop_Jframe - Fatal编程技术网

在数组中存储对象并显示它们(Java)

在数组中存储对象并显示它们(Java),java,oop,jframe,Java,Oop,Jframe,我正在做一个java井字游戏。首先,我为按钮创建了一个类,然后尝试存储该类的实例数组。在我将这些对象添加到框架之前,一切都很正常。这是我的密码: package tictactoe; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class TicTacToe extends JFrame { TicTacToe() { this.setLayout(null);

我正在做一个java井字游戏。首先,我为按钮创建了一个类,然后尝试存储该类的实例数组。在我将这些对象添加到框架之前,一切都很正常。这是我的密码:

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();

    }

}

PlayingButton类应扩展JComponent或其子类。

PlayingButton类应扩展JComponent或其子类。

然后,会发生什么?您希望代码做什么,它做什么?什么是
播放按钮
?怎么搞的?有堆栈跟踪吗?PlayingButton是我创建的另一个类,用于从中获取对象。@M-AmrMoussa是的,但是如果我们看不到它是如何编码的,我们该如何发现它的问题呢?你需要提供一个答案,然后,会发生什么?您希望代码做什么,它做什么?什么是
播放按钮
?怎么搞的?有堆栈跟踪吗?PlayingButton是我创建的另一个类,用于从中获取对象。@M-AmrMoussa是的,但是如果我们看不到它是如何编码的,我们该如何发现它的问题呢?你需要提供一个
this.add(b[0]);