Create check box using JCheckBox

Source code below will show you, how to create a check box in java with text HI using JCheckBox.

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


import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class CreateCheckBoxUsingJCheckBox
{
public static void main(String[]args)
{
//Create check box with text HI
JCheckBox checkBox=new JCheckBox("HI");

//Create JFrame to place created JCheckBox
JFrame frame=new JFrame("Create check box using JCheckBox");

//add created check box into JFrame
frame.add(checkBox);

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

//set JFrame size
frame.setSize(450,65);

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


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

Create check box in java

In java, you can create check box using JCheckBox class.

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
***************************************************************************

Why we use JLabel

JLabel is use when you want to add text or image into you graphical user interface.

Create text area using JTextArea

Source code below will show you how to create text area in java using JTextArea class.

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


import javax.swing.JTextArea;
import javax.swing.JFrame;

public class CreateTextAreaUsingJTextArea
{
public static void main(String[]args)
{
//Create text area without initial text using JTextArea
JTextArea textArea=new JTextArea();

//Create a JFrame that will be use to place JTextArea
JFrame frame=new JFrame("Create text area using JTextArea");

//Add text area into JFrame
frame.add(textArea);

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

//set JFrame size
//WIDTH = 500 pixels
//HEIGHT = 500 pixels
frame.setSize(500,500);

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


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

Create text area in java

In java, you can create text area using JTextArea class.

Create text field using JTextField

Source code below will show you, how to create text field in java using JTextField class.

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


import javax.swing.JTextField;
import javax.swing.JFrame;

public class CreateTextFieldUsingJTextField
{
public static void main(String[]args)
{
//Create a text field with no initial text in it
JTextField textField=new JTextField();

//Create a JFrame that will be use to place created text field
JFrame frame=new JFrame("Create text field using JTextField");

//add created JTextField into JFrame
frame.add(textField);

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

//set JFrame size
//WIDTH = 400 pixels
//HEIGHT = 65 pixels
frame.setSize(400,65);

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


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

Create text field in java

In java, you can create text field using JTextField class.

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
**************************************************************************

Create button in java

In java, you can create button using JButton class.

RELAXING NATURE VIDEO