How do I make this button work?

By Skylar

I’m making a push counter application and can’t get the button to work. I’ve researched a lot of ActionListener tutorials online but can’t figure out what’s wrong with my code. It appears to me as though it should work!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PushCounter
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("Push Counter");
        JPanel panel = new JPanel();
        JLabel label = new JLabel("Counter");
        JTextField textArea = new JTextField(7);
        JButton button = new JButton("Count");
        panel.add(label);
        panel.add(textArea);
        panel.add(button);
        frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true);
        ButtonListener listener = new ButtonListener();
        button.addActionListener(listener);
        final class ButtonListener implements ActionListener
        {
            int count = 0;
            @Override
            public void actionPerformed(ActionEvent event)
            {
                count++;
                textArea.setText(Integer.toString(count));
            }
        }
    }
}

It keeps saying ButtonListener cannot be resolved to a type

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273