Ask your own question, for FREE!
Design 6 Online
OpenStudy (anonymous):

How do I create a JFrame that includes a JLabel that reads “Hello, World"

thomaster (thomaster):

``` import java.awt.*; import javax.swing.*; public class TopLevelWindow { private static void createWindow() { JFrame frame = new JFrame("Frame name"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE); JLabel textLabel = new JLabel("Hello, World",SwingConstants.CENTER); textLabel.setPreferredSize(new Dimension(300, 100)); frame.getContentPane().add(textLabel, BorderLayout.CENTER); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { createWindow(); } }

OpenStudy (anonymous):

I tried using this example but it didn't work in NetBeans. In order for me to create a project, it also creates a package. Maybe this has something to do with it? Not sure but what other suggestions can you offer?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!