Below code shows how to add ActionListener to a JButton /** * * @author Eric * site:www.download-all.net */ import javax.swing.J...
/** * * @author Eric * site:www.download-all.net */ import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class JButtonListener extends JFrame implements ActionListener{ public JButton button; public int count=0; JButtonListener() { super(); setSize(300,300); setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button=new JButton("Ok"); button.setBounds(10, 10, 200, 20); button.addActionListener(this); add(button); setVisible(true); } public void actionPerformed(ActionEvent event) { count++; button.setText("Clicked "+ count); } public static void main(String args[]) { new JButtonListener(); } }