Create JPanel in java

Source code below will show you how to create a JPanel in java and after that we will put the JPanel into a JFrame.

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


import javax.swing.JFrame;
import javax.swing.JPanel;

public class CreateAJPanel
{
public static void main(String[]args)
{
//Create a JPanel
JPanel panel=new JPanel();

//Create a JFrame that we will use to add the JPanel
JFrame frame=new JFrame("Create a JPanel");

//ADD JPanel INTO JFrame
frame.add(panel);

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

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

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


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

RELAXING NATURE VIDEO