How to write events
this is a sample . i want to click and it gives me number of times clicked.
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
//import javax.swing.event;
public class Beep extends JFrame implements ActionListener {
JButton btn;
public static final int ACTION_FIRST;
public Beep() {
super("Try");
Container c = getContentPane();
c.setLayout(new BorderLayout());
btn = new JButton(ACTION_FIRST);
btn.setLayout(new FlowLayout());
btn.setActionCommand("Prees");
btn.addActionListener(this);
c.add(btn, BorderLayout.SOUTH);
setSize(200,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
str = "ACTION";
str = btn.getActionCommand();
}
public static void main(String args[]) {
Beep beep = new Beep();
beep.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
|