我正在尝试构建一个棋盘,但我不断收到一个似乎无法修复的错误。
我试图找到它可能是什么,但我只是失去了。
我的代码:
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
public class chess extends JFrame {
int column_want, column_curr, column_diff;
int row_want, row_curr, row_diff;
public static void main(String[] args) {
System.out.println("Welcome to java");
board frame = new boardLayout();
frame.setSize(500, 500);
frame.setTitle("chess Board");
frame.setLocationRelativeTo(null); //center of frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void boardLayout() {
JPanel board = new JPanel(new GridLayout(6,5,1,1)); // gridLayout (row, column, hgap, vgap)
add(board, BorderLayout.NORTH);
}
}
它声称在第12行,但是我不知道为什么那里可能有错误。
第12行:
board frame = new boardLayout();
您声明一个type board
,该类型既不在导入中,也不在文件中。然后,您尝试创建class的实例,该实例boardLayout
与类型一样是未知的。
public void boardLayout()
是一个方法声明,除非它与其所属的类具有相同的名称,否则它将不能用作构造函数,并且您将删除返回类型void
。像public chess()
。
众所周知,构造函数确实声明了其返回类型,即返回了实例化的对象。因此new chess()
将返回一个类型的新对象chess
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句