Java: Swing

This entry is part 3 of 54 in the series Learn Java

Our tutorial here is meant to learn the fundamentals of Java programming and if you look at my another tutorials on WPF, you will know that we can develop Windows UI using XAML.

The alternative to WPF in Java is JavaFX.  If you are new to Java programming, I actually suggest that you start learning JavaFX rather than Java Swing.  Swing is still very popular and there are still many programmers using it.  However, Oracle has put it in maintenance mode.  It will be replaced by JavaFX and I will work out a tutorials on JavaX soon.

We still have to learn Java Swing if you want to have a good grasp of Java UI programming and here, let’s use the following simple example to illustrate it.

Code Block
package javaapplication3;

import javax.swing.*;

public class JavaApplication3 {

    public static void main(String[] args) {
        JFrame frame = new JFrame( "HelloJava" );
        JLabel label = new JLabel("Hello, I am a Java Program!", JLabel.CENTER );
        frame.setSize( 300, 300 );
        frame.setVisible( true );

In this program, the windows is formed by using the JFrame class.  We create an instance, called frame of the class JFrame.

The same goes to the text or the label that will go into the windows.  This is done by using the JLabel class.



Series Navigation<< Java: Build and run java program like an executable
Java: Passing arguments to main >>

Leave a comment

Leave a Reply