java - Eclipse JFrame 错误

标签 java eclipse variables jframe

我在使用 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/

相关文章:

java - 如何通过 Selenium WebDriver (Java API) 在 Web View 中查找 Web 元素?

java - 使用 Mockito 的 GWT MVP 测试用例,其中包含 Activity 和 Places 以及 GIN

java - setText 函数不会改变 TextView

java - Android .apk 大小加倍,具体取决于自 v17 工具以来用于部署的开发盒

java - 有效使用 Eclipse

Android SDK 日志显示 : "Download interrupted: Connection to https://dl-ssl.google.com refused", 可以做什么?

python - 逐行读取文件时出现名称未定义错误python

php - 如何将 php session 变量从页面传输到页面内的 iframe

java - Java Petstore 2.0 蓝图

javascript - JS : Changing variable wont apply on next