This is ClickMe program where it's suppose to change button text once the user clicks the button. Although, program does successfully launch and pops up the "Click ME" button but once it's clicked nothing happens, it doesn't change anything. Any help would be appreciated.
import javax.swing.*;
import java.awt.event.*;
public class MyResponse extends JFrame implements ActionListener
{
public static void main(String[] args)
{
new MyResponse();
}
private JButton button;
public MyResponse()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(200,100);
this.setVisible(true);
this.setTitle("Click Program");
JPanel panel = new JPanel();
JButton button = new JButton ("Click ME!!");
button.addActionListener(this);
panel.add(button);
this.add(panel);
}
private int clickCount = 0;
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button)
{
clickCount ++;
if (clickCount == 1)
button.setText("You just clicked me");
else
button.setText(" You have clicked me " +clickCount+ "times!");
}
}
}