我正在启动一个新程序,由于某种原因,当我尝试编译它时出现以下错误:
3D.java:4: error: <identifier> expected
public class 3D {
^
3D.java:5: error: illegal start of expression
public static void main(String[] args){
^
3D.java:5: error: illegal start of expression
public static void main(String[] args){
^
3D.java:5: error: ';' expected
public static void main(String[] args){
^
3D.java:5: error: '.class' expected
public static void main(String[] args){
^
3D.java:5: error: ';' expected
public static void main(String[] args){
^
3D.java:20: error: reached end of file while parsing
}
^
7 errors
这是我的代码:
import java.awt.Canvas;
import java.swing.JFrame;
public class 3D {
public static void main(String[] args){
int height = 400;
int width = 600;
String title = "3D Game";
JFrame f = new JFrame();
f.setSize(width, height);
f.setVisible(true);
f.setTitle(title);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
}
}
我并没有真正做太多,我不确定这些错误来自哪里,因为我没有尝试在方法中声明方法或类似的东西。因此,我们将不胜感激。