Learn Writing Java Hello World Swing GUI Program

Java Hello World Swing GUI Program – Write first hello world program using Java Swing framework. Learn how to use Label and Text Fields in Java Swing.

If you feel this video is useful, Please share it with your friends on Facebook, twitter Google plus etc.

Code developed in this tutorial provided below:

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class HelloWorldSwing {
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setSize(300, 300);
        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label, BorderLayout.BEFORE_FIRST_LINE);
        JTextField text = new JTextField();
        frame.getContentPane().add(text, BorderLayout.AFTER_LAST_LINE);
        //Display the window.
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {

For further reading refer Java Programming Category posts.

Share this post

Learning Java Hello World Swing GUI Program
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *