Sunday, 18 December 2022

write a program to count the number of clicks performed by the user in a frame window (using Swing in java )

 

write a program to count the number of clicks performed by the user in a frame window

(using Swing in java )



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

class CounterTest extends JFrame implements ActionListener {
    private int count = 0;
    JLabel lblData;
    CounterTest ()
    {setLayout(new FlowLayout());
        lblData = new JLabel("button clicked a times");
        JButton btn = new JButton("Click me");
        btn.addActionListener((ActionListener) this);
        add(lblData);
        add(btn);

    }
    public void actionPerformed(ActionEvent e) {
        count++;
        lblData.setText(" Button clicked " + count + "times");

    }

    public static void main(String args[]) {

        CounterTest  ex = new CounterTest();
        ex.setVisible(true);
    }
}




OUTPUT:  







No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...