我在使用 Eclipse 时遇到此错误。有什么想法吗?
import java.awt.*;
import javax.swing.*;
public class Main {
JFrame frame;
frame.setTitle("Elevator build 11");
frame.setPositionRelativeTo(null);
frame.setVisible(true);
}
最佳答案
您的代码需要位于方法内部。尝试将其放在 main 方法中。另外,您需要首先实例化您的框架。
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame(); //instantiate frame
// set the title
// set the position
// set it visible
}
}
关于java - Eclipse JFrame 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640402/