Friday, 1 January 2016

How to implement JCheckbox to make check boxes in Java.

. To make check boxes in java use following code

Code:

import javax.swing.*;
import java.awt.*;

public class JCheckDemo
{

   public static void main(String[] args)
   {

     JFrame f1;

     f1 = new JFrame("Welcome");

      JLabel l1 = new JLabel("Choose different one.");

     JCheckBox cb1 = new JCheckBox("Apple");
     JCheckBox cb2 = new JCheckBox("Mango");
     JCheckBox cb3 = new JCheckBox("Chicken");

    f1.add(l1);
    f1.add(cb1);
    f1.add(cb2);
    f1.add(cb3);
     f1.setLayout(new FlowLayout(FlowLayout.LEFT));
     f1.setVisible(true);
     f1.setSize(400,100);
     f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   
    }
 }

Output:


No comments:

Post a Comment