작업중인 GUI 생성자에 문제가 있습니다. 그것은 tic tac toe 게임에 대한 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"라는 이름을 지정하면 생성자가되지 않습니다. 그래서 그것을 생성자라고 부르지 마십시오 (이것은 단지 것들을 혼란시킬 것입니다). 당신이 명시 적으로 호출해야만하는 오래된 방법 일뿐입니다. 관련 정보 나 코드를 충분히 포함시키지 않았거나 문제의 성격을 기술하여 많은 도움을받을 수 있습니다. –