Select all JCheckBox in one click

Watch video below :


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

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

import java.awt.GridLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JCheckBoxMultipleSelectInOneClick extends JFrame implements ActionListener
{
 //Create JCheckBox object
 JCheckBox a=new JCheckBox("Select All");
 JCheckBox b=new JCheckBox("Car");
 JCheckBox c=new JCheckBox("Lorry");
 JCheckBox d=new JCheckBox("Motorcycle");
 
 //Constructor for JCheckBoxMultipleSelectInOneClick class
 public JCheckBoxMultipleSelectInOneClick()
 {
  //Set JFrame title
  super("Select All JCheckBox In One Click");
  
  //Set JFrame layout
  setLayout(new GridLayout(4,1));
  
  //Add action listener to JCheckBox a
  a.addActionListener(this);
  
  //Add JCheckBox into JFrame
  add(a);
  add(b);
  add(c);
  add(d);
  
  //Set JFrame's default close operation when click on close window button
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  //Set JFrame size
  setSize(400,400);
  
  //Make JFrame locate at the center of screen
  setLocationRelativeTo(null);
  
  //Make JFrame visible to see
  setVisible(true);
 }
 
 //Override actionPerformed method in ActionListener interface
 public void actionPerformed(ActionEvent e)
 {
  if(e.getSource()==a)
  {
   //Set all JCheckBox to select when JCheckBox a is select  
   if(a.isSelected()==true)
   {
    b.setSelected(true);
    c.setSelected(true);
    d.setSelected(true);
   }
   
   //Set all JCheckBox to unselect when JCheckBox a is select 
   else
   {
    b.setSelected(false);
    c.setSelected(false);
    d.setSelected(false);
   }
  }
 }

 //Main method where this program start
 public static void main(String[]args)
 {
  JCheckBoxMultipleSelectInOneClick myFirstObject = new JCheckBoxMultipleSelectInOneClick();
 }
}


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

RELAXING NATURE VIDEO