Java Swing: A Hello World GUI App (Video Tutorial Part 1)

Interested in GUI programming in Java? In this tutorial I show you how to build up a minimal “Hello World” user interface (Swing) app in Java.

After starting the video, click the maximise button to make it fullscreen so you can see the code!

Code For This Tutorial

import javax.swing.JFrame;
import javax.swing.SwingUtilities;


public class App {


	public static void main(String[] args) {
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame("Hello World Swing!");
				frame.setSize(500, 400);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
			}
		});
	}

}

Learn to program Java Swing with my complete video course – desktop programming and applets. Includes 7 free videos. Click here for details.

All pages on this site are copyright © 2013 John W. Purcell

4 Responses to Java Swing: A Hello World GUI App (Video Tutorial Part 1)

  1. C@N says:

    Hi John.

    Could please explain more briefly the usage of SwingUtilities.invokeLater…

    What’s exactly going wrong under the hood when we don’t use it.

    Thanks, C@N.

    • Squiffy says:

      Hi C@N, it’s basically running a special thread. But as to what happens if you don’t use it to start your application, it’s fair to say that it’s a mystery to most of us. Sun/Oracle themselves are vague about it. Perhaps there might be some circumstance under which your program will crash without it, but I’ve yet to find it.

  2. nazo says:

    my man you are only perfect.thanks for this website

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Posted in Java, Java Swing (GUI), Java Video Tutorials (Advanced) | Tagged , , , , |