Create button using JButton

Source code below will show you, how to create button in Java using JButton class.

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


import javax.swing.JButton;
import javax.swing.JFrame;

public class CreateButtonUsingJButton
{
public static void main(String[]args)
{
//Create button using JButton
//Button that we create contain text My first button
JButton myButton=new JButton("My first button");

JFrame frame=new JFrame("Create button using JButton");

//add button that we create in JFrame
frame.add(myButton);

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

//set JFrame size
//WIDTH = 300 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