Write a program to count the number of clicks performed by the user in a frame window This program run on Eclipse IDE.
package com.javaguides.javaswing.login;
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");
}
No comments:
Post a Comment