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