gpt4 book ai didi

Java游戏无法运行

转载 作者:行者123 更新时间:2023-12-01 17:13:59 26 4
gpt4 key购买 nike

这就是我的游戏...

import javax.swing.JFrame;

public class Main extends JFrame {

//the parts of the game like the parts in a desktop
public void Skeleton() {
//entry point of the game
add(new Board());
// sets the title
setTitle("Skeleton");
// makes it safe for the program to close without leaks
setDefaultCloseOperation(EXIT_ON_CLOSE);
//sets the size
setSize(300, 280);
//sets the location
//null means middle
setLocationRelativeTo(null);
//set the window to be visible
setVisible(true);
//allows the window to be resized if the statement is true
setResizable(false);
}

//wraps everything up
public static void main(String[] args) {
new Skeleton();
}
}

new Skeleton(); 出现错误,错误提示为

Skeleton cannot be resolved to a type

最佳答案

你的骨架method ,不是class 。只有类可以被实例化。我相信您想要做的是:

public static void main(String[] args) {
Main mainFrame = new Main();
mainFrame.Skeleton(); // I assume you were trying to ultimately call this method.
}

旁注:在 Java 中,标准方法以小写字母开头,因此您的 Skeleton 应该是 骨骼。两者在技术上、语法上都是有效的,但正如我所说,后者是标准,当遵循标准时,它可以让其他人(甚至你自己)更容易地查看你的代码,从而快速阅读和理解它。实际上,我发现当您混合这样的情况时,很难知道您何时正在查看类、方法或对象。

编辑:正如 JasonC 指出的那样,当存在不正确的情况时,StackOverflow 语法荧光笔会变得非常困惑,这说明了我在上一段中提到的内容,这使得其他人阅读起来更加困难(尤其是在一眼)。

关于Java游戏无法运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22869380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com