Java编译器无法解析被覆盖JButton的符号

Java编译器无法解析被覆盖JButton的符号,java,swing,inheritance,compiler-errors,jbutton,Java,Swing,Inheritance,Compiler Errors,Jbutton,我正在编写一个编辑器,它创建一个按钮矩阵。单击时,按钮的显示符号会发生变化。所以我创建了一个扩展JButton的新类,并做了一些更改。 编译编译器时告诉我,它无法解析符号AlienGameButton。但是为什么呢?我怎样才能解决这个问题 package MapGenerator; import javax.swing.*; import javax.swing.JOptionPane; import java.awt.*; public class MapGenerator { public

我正在编写一个编辑器,它创建一个按钮矩阵。单击时,按钮的显示符号会发生变化。所以我创建了一个扩展JButton的新类,并做了一些更改。 编译编译器时告诉我,它无法解析符号AlienGameButton。但是为什么呢?我怎样才能解决这个问题

package MapGenerator;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.*;

public class MapGenerator {
public static void main(String[] args) {


    //Initialisierung der Mapgröße über einen Input-Dialog

    int hight, width;
    hight = Integer.parseInt(JOptionPane.showInputDialog(null, "Höhe des Spielfeldes: "));
    width = Integer.parseInt(JOptionPane.showInputDialog(null, "Breite des Spielfeldes: "));
    System.out.println(width);
    System.out.println(hight);


    //Erstellen eines Fensters abhängig von der Anzahl der gewünschten Felder

    JFrame GeneratorFenster = new JFrame("Map Generator");
    GeneratorFenster.setSize(hight * 50 + 50, width * 50);
    GeneratorFenster.setVisible(true);

    AlienGameButton buttons[][] = new AlienGameButton[hight][width];

    GeneratorFenster.setLayout(new GridLayout(hight, width));
    for (int i = 0; i < hight; i++) {
        for (int j = 0; j < width; j++) {
            buttons[i][j] = new AlienGameButton();
            GeneratorFenster.add(buttons[i][j]);
        }

        GeneratorFenster.setVisible(true);

    }
}
}
以下是编译器错误:

MapGenerator.java:26: error: cannot find symbol
AlienGameButton buttons[][] = new AlienGameButton[hight][width];
^
symbol:   class AlienGameButton
location: class MapGenerator
MapGenerator.java:26: error: cannot find symbol
AlienGameButton buttons[][] = new AlienGameButton[hight][width];
                                  ^
symbol:   class AlienGameButton
location: class MapGenerator
MapGenerator.java:31: error: cannot find symbol
buttons[i][j] = new AlienGameButton();
                            ^
symbol:   class AlienGameButton
location: class MapGenerator
3 errors

正如在评论中提到的,如果您想尝试使用javac FileName.java编译,它将无法工作。请使用以下两个命令使其工作:

javac MapGenerator/AlienGameButton.java
javac MapGenerator/MapGenerator.java
而不是

javac AlienGameButton.java
javac MapGenerator.java
另外,正如您所说的,当您将其移动到src目录时,它开始工作,这是因为随后包被更改为默认包

附言:

一些建议和编码标准:

包名称和类名不应完全相同

包名 应始终以小写字母开头,类名应始终 从大写字母开始


请包含完整的编译错误。关于你的代码的一些评论:德语和英语的混合让人非常困惑。选择一个(最好是英语)并坚持下去Package、variable、field和MethodName应始终以小写字母开头。附带说明:您不应该为此重写JButton,因为您没有更改JButton的固有行为,只是附加了一个ActionListener。此外,你还需要学习和使用。变量名都应该以小写字母开头,而类名应该以大写字母开头。学习并遵循这一点可以让我们更好地理解您的代码,也可以让您更好地理解其他人的代码。请查看提示:添加@HovercraftFullOfEels(或任何人,
@
很重要)以通知此人新的评论。“我在博客2添加了完整的错误消息”什么是“博客2”?只是为了确定:
MapGenerator.java
AlienGameButton.java
在同一个目录中?非常感谢您的帮助!
javac AlienGameButton.java
javac MapGenerator.java