adrian
adrian

Reputation: 4594

create a simple label in java

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?

Upvotes: 0

Views: 772

Answers (2)

Michael Borgwardt
Michael Borgwardt

Reputation: 346417

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?

Upvotes: 1

dogbane
dogbane

Reputation: 274768

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).

Upvotes: 2

Related Questions