用java创建一个简单的标签
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您正在运行的内容,因为看起来您正在运行 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
).看起来您正在将程序作为 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?