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

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



                   JRadioButton radioButton2 = new JRadioButton(“Female”);

                   JButton submitButton = new JButton(“Submit”);


                   ButtonGroup group = new ButtonGroup();

                   group.add(radioButton1);
                   group.add(radioButton2);



                   submitButton.addActionListener(new ActionListener() {
                       @Override
                       public void actionPerformed(ActionEvent e) {

                           String selectedOption = radioButton1.isSelected() ? “Male” : “Female”;
                           JOptionPane.showMessageDialog(frame, “Selected Option: “ + selectedOption);

                       }
                   });



                   frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
                   frame.getContentPane().add(radioButton1);
                   frame.getContentPane().add(radioButton2);

                   frame.getContentPane().add(submitButton);
                   frame.setSize(300, 200);
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                   frame.setVisible(true);
               }

           }
                ीकरण:
              1    इंपोट  िववरण :

                  import javax.swing.*;
                  import java.awt.event.ActionEvent;
              import java.awt.event.ActionListener;



                ंग घटकों और ईव ट ह डिलंग के  िलए आव क पैके ज इंपोट  कर ।
              2    ास प रभाषा:

                  public class RadioButtonControlExample {
                  RadioButtonControlExample नामक एक  ास प रभािषत कर ।
              3   मेन िविध:

                  public static void main(String[] args) {
                  Start the main method.



                                                           201

                                  CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 117
   210   211   212   213   214   215   216   217   218   219   220