JFrame window doesn't show up

Harry Holmes :

I'm learning basic Java GUI programming from a tutorial, and this code is supposed to generate a window with a title, some text, and some tooltip text. It doesn't generate anything. Can anyone tell me why it isn't working?

//In a class called apples:

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class apples extends JFrame {

    private JLabel item1;

    public apples() {
        super("Title");
        setLayout(new FlowLayout());

        item1 = new JLabel("This is some displayed text");
        item1.setToolTipText("This is some tooltip text.");
        add(item1);
    }

}


//In the main class class1:
import javax.swing.JFrame;

class class1 {
    public static void main(String args[]) {

        apples green = new apples();
        green.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

}

Madplay :

Can you try like below?

class Class1 {
    public static void main(String args[]) {
        apples green = new apples();
        green.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        green.setSize(1000, 500); // set window's size.
        green.pack(); // packs the components closely together.
        green.setVisible(true); // makes the window visible.
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=149867&siteId=1