私が取り組んでいるGUIコンストラクタに問題があります。チックタックトーゲームのGUIになっていますが、私のボタンは作成されておらず、GUIウィンドウも空白です。私は本当に混乱しています。私はTicTacToePanelのインスタンスを作成し、それをメインのJFrameに追加します。Java:コンストラクタが動作しません
class TicTacToePanel extends JPanel implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
//Creates the button array using the TicTacToeCell constructor
private TicTacToeCell[] buttons = new TicTacToeCell[9];
//(6) this constructor sets a 3 by 3 GridLayout manager in the panel
///then creates the 9 buttons in the buttons arrray and adds them to the panel
//As each button is created
///The constructer is passed a row and column position
///The button is placed in both the buttons array and in the panels GridLayout
///THen an actionListener this for the button
public void ButtonConstructor() {
//creates the layout to pass to the panel
GridLayout mainLayout = new GridLayout(3, 3);
//Sets a 3 by 3 GridLayout manager in the panel
this.setLayout(mainLayout);
int q = 1; //provides a counter when creating the buttons
for (int row = 0; row < 3; row++) //adds to the current row
{
for (int col = 0; col < 3; col++) //navigates to the correct columns
{
System.out.println("Button " + q + " created");
buttons[q] = new TicTacToeCell(row, col);
mainLayout.addLayoutComponent("Button " + q, this);
this.add(buttons[q]); //adds the buttons to the ticTacToePanel
buttons[q].addActionListener(this); //this sets the panel's action listener to the button
q++; //increments the counter
}
}
}
}
ボタン作成ルーチンを呼び出す 'TicTacToePanel'コンストラクタが見つかりません!! – Favonius
「TicTacToeCell」はどこに定義されていますか?いくつかのコードが役に立ちます。 – casablanca
「ButtonConstructor」という名前を付けても、コンストラクタにはなりません。だから、コンストラクタと呼んではいけません。明示的に呼び出さなければならない古いメソッドです。関連する情報やコードを十分に記載しておらず、多くの助けが必要なほど問題の性質を説明していません。 –