Page 212 - CITS - CSA - TP (Volume 2) - Hindi
P. 212

कं  ूटर सॉ वेयर ए ीके शन - CITS



           अ ास 117 : कु छ कं ट  ोल वाला एक कं टेनर बनाएँ  (Create a container with a few controls)


            उ े
           इस अ ास के  अंत म  आप यह कर सक  गे
           •  कु छ कं ट ोल के  साथ एक कं टेनर बनाने के  िलए Java  ो ाम डेवलप कर

           आव कताएं  (Requirements)

           उपकरण/साम ी (Tools/Materials)
           •  िवंडोज OS वाला PC/लैपटॉप
           •   SDK सॉ वेयर
           •   टे  एिडटर (िवजुअल  ू िडयो/सबलाइम/नोटपैड)

            ि या (Procedure)


           टा  1: म ी  चयन के  िलए JCheckBox बनाएँ
           Code:
           import javax.swing.*;

           import java.awt.event.ActionEvent;
           import java.awt.event.ActionListener;
           public class CheckBoxControlExample {

               public static void main(String[] args) {
                   // Create a JFrame (window) with the title “CheckBox Example”
                   JFrame frame = new JFrame(“CheckBox Example”);



                   // Create two JCheckBox components with labels “Option 1” and “Option 2”

                   JCheckBox checkBox1 = new JCheckBox(“Option 1”);
                   JCheckBox checkBox2 = new JCheckBox(“Option 2”);


                   // Create a JButton with the label “Submit”

                   JButton submitButton = new JButton(“Submit”);



                   // Add an ActionListener to the submitButton
                   submitButton.addActionListener(new ActionListener() {
                       @Override

                       public void actionPerformed(ActionEvent e) {
                           // Create a StringBuilder to build the message
                           StringBuilder selectedOptions = new StringBuilder(“Selected Options: “);



                           // Check if checkBox1 is selected and append the corresponding text
                           if (checkBox1.isSelected()) {



                                                           198
   207   208   209   210   211   212   213   214   215   216   217