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

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






                   // Setting layout to FlowLayout
                   frame.setLayout(new FlowLayout());


                   // Adding components to the frame
                  frame.add(nameLabel);
                   frame.add(nameTextField);

                   frame.add(submitButton);



           // Adding action listener to the button
                   submitButton.addActionListener(new ActionListener() {

                       @Override
                       public void actionPerformed(ActionEvent e) {
                           String name = nameTextField.getText();
                           System.out.println(“Name submitted: “ + name);
                           showConfirmationDialog(“Submission”, “Name submitted: “ + name);
                       }

                   });


                   // Adding event handler to the text field
                   nameTextField.addActionListener(new ActionListener() {
                       @Override

                       public void actionPerformed(ActionEvent e) {
                      String name = nameTextField.getText();
                          System.out.println(“Enter key pressed in the text field. Name: “ + name);
                   showConfirmationDialog(“Text Field Event”, “Enter key pressed. Name: “ + name);
                       }
                   });



                   // Setting frame visibility
                   frame.setVisible(true);


                   // Adding window close event handling
                   frame.addWindowListener(new java.awt.event.WindowAdapter() {

                       public void windowClosing(java.awt.event.WindowEvent windowEvent) {
                           System.exit(0);
                       }
                   });
              }



                                                           207

                                  CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 118
   216   217   218   219   220   221   222   223   224   225   226