Create label using JLabel

Source code below will show you, how to create label in java using JLabel. We will use JLabel when we want to add text or image into graphical user interface.

***************************************************************************
COMPLETE SOURCE CODE FOR : CreateLabelUsingJLabel.java
***************************************************************************


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

public class CreateLabelUsingJLabel
{
public static void main(String[]args)
{
//Create a label with text My First Label using JLabel
JLabel label=new JLabel("My First Label");

//Create a JFrame that we will use to place JLabel
JFrame frame=new JFrame("Create label using JLabel");

//Add created label into JFrame
frame.add(label);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size to :
//WIDTH = 400 pixels
//HEIGHT = 100 pixels
frame.setSize(400,100);

//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}


***************************************************************************
JUST COMPILE AND EXECUTE IT
***************************************************************************

RELAXING NATURE VIDEO