Put JLabel into JFrame

Source code below will show you, how to add a JLabel into JFrame.

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


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

public class AddJLabelIntoJFrame
{
public static void main(String[]args)
{
//Create a JLabel with text HI that we want to add into JFrame
//SwingConstants.CENTER will make HI locate at the center of JLabel
JLabel label=new JLabel("HI",SwingConstants.CENTER);

//Create a JFrame that will be a window
//Window title is, Put JLabel into JFrame
JFrame frame=new JFrame("Put JLabel into JFrame");

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

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

//Set size for JFrame in pixels
//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