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
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.
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.
All right. Thanks a lot.
my man you are only perfect.thanks for this website