Page 220 - CTS - CSA TP - Volume 2
P. 220

COMPUTER SOFTWARE APPLICATION - CITS



           Output:










































           TASK 2:  Button Selection with Action Listener
           import javax.swing.*;
           import java.awt.event.ActionEvent;
           import java.awt.event.ActionListener;



           public class ButtonClickExample {


               public static void main(String[] args) {
                   JFrame frame = new JFrame(“Button Click Example”);
                   JButton button = new JButton(“Click me”);



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

                           JOptionPane.showMessageDialog(null, “Button clicked!”);
                       }
                   });









                                                           205

                              CITS : IT & ITES - Computer Software Application - Exercise 118
   215   216   217   218   219   220   221   222   223   224   225