title: Java: Counting clicks on button
body: <p>I am trying to do something similiar as cookie clicker, nevertheless it does not work. I have not managed to create a "counter" that shows the amount of clicks. This is what I got hitherto, any ideas?</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  public class Stocks implements ActionListener {
  
  public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
              new Stocks().createGui();
          }
      });
  
  }
  
  public void createGui() {
      JFrame frame = new JFrame("Clicker");
      frame.setSize(175, 200);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel panel = new JPanel(new GridBagLayout());
      frame.add(panel);
      frame.getContentPane().add(panel, BorderLayout.WEST);
      GridBagConstraints c = new GridBagConstraints();
  
      JButton button1 = new JButton("Click this");
      c.gridx = 0;
      c.gridy = 0;
      c.insets = new Insets(40, 40, 40, 40);
      panel.add(button1, c);
      button1.addActionListener(this);
  
  }
  </code></pre>