title: Button Counter-Java
body: <p>I need help making a program that has 2 button. A message appears “I was clicked n time!” whenever the button is clicked. Each button should have a separate click count.</p>
  
  <pre><code>    import java.awt.event.ActionListener;
      import javax.swing.JButton;
      import javax.swing.JFrame;
  
      public class ButtonViewer
      {
        private static final int FRAME_WIDTH = 400;
        private static final int FRAME_HEIGHT = 360;
  
  
   public static void main(String[] args)
   {
       int counter1 = 0;
       int counter2 = 0;
  
       JFrame frame = new JFrame();
       JButton button = new JButton("Click me!");
       frame.add(button);
  
       JFrame frame2 = new JFrame();
       JButton button2 = new JButton("Click me too!");
       frame2.add(button2);
  
       ActionListener listener = new ClickListener();
       button.addActionListener(listener);
       button2.addActionListener(listener);
  
       counter1++;
       counter2++;
  
       frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
  
       frame2.setSize(FRAME_WIDTH, FRAME_HEIGHT);
       frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame2.setVisible(true);
   }
  }
  </code></pre>