用java创建一个简单的标签

发布于 2024-12-27 16:35:37 字数 652 浏览 3 评论 0原文

在 Eclipse 中我已经这样做了:

import javax.swing.JFrame;
import javax.swing.JLabel;

//import statements
//Check if window closes automatically. Otherwise add suitable code
public class HelloWorldFrame extends JFrame {

    public static void main(String args[]) {
        new HelloWorldFrame();
    }
    HelloWorldFrame() {
        JLabel jlbHelloWorld = new JLabel("Hello World");
        add(jlbHelloWorld);
        this.setSize(100, 100);
        // pack();
        setVisible(true);
    }
}

但是没有显示标签,我的意思是什么也没有出现。 只有控制台显示这一点:

JUnit version 4.10

Time: 0.001

OK (0 tests)

有人知道为什么吗?

In eclipse I've done this:

import javax.swing.JFrame;
import javax.swing.JLabel;

//import statements
//Check if window closes automatically. Otherwise add suitable code
public class HelloWorldFrame extends JFrame {

    public static void main(String args[]) {
        new HelloWorldFrame();
    }
    HelloWorldFrame() {
        JLabel jlbHelloWorld = new JLabel("Hello World");
        add(jlbHelloWorld);
        this.setSize(100, 100);
        // pack();
        setVisible(true);
    }
}

But there is no label shown, I mean nothing appears.
Only the console shows this:

JUnit version 4.10

Time: 0.001

OK (0 tests)

Has anyone any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一百个冬季 2025-01-03 16:35:37

检查您正在运行的内容,因为看起来您正在运行 JUnit 测试,而不是此类。检查您的运行配置以确保您正在将此类作为 Java 应用程序运行。

在 Eclipse 编辑器中打开此类后,转到 Run 菜单,选择 Run as 项,然后选择 Java application(或 Alt+Shift+X,J)。

Check what you are running, because it looks like you are running a JUnit test, not this class. Check your Run Configurations to make sure that you are running this class as a Java Application.

With this class open in the Eclipse editor, go to the Run menu, select the Run as item and then Java application (or Alt+Shift+X,J).

撧情箌佬 2025-01-03 16:35:37

看起来您正在将程序作为 JUnit 测试套件而不是 Java 应用程序来运行。你究竟是如何启动它的,使用什么 IDE?

It looks like you're running your program as a JUnit test suite rather than a Java application. How exactly are you starting it, using what IDE?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文