Site hosted by Angelfire.com: Build your free website today!
 

Swing Hello World

import javax.swing.*;        

public class HelloWorldSwing {
    public static void main(String[] args) {
        JFrame frame = new JFrame("HelloWorldSwing");
        final JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);
        frame.setDefaultCloseOperation(
            JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}

Note

The pack method sizes the frame so that all its contents are at or above their preferred sizes. An alternative to pack is to establish a frame's size explicitly by calling setSize.

The setVisible method makes the frame appear onscreen.

The setDefaultCloseOperation method to configure the default action for when the user clicks the close button. See WindowConstants