I have it working to show that the button is being pushed but I cannot figure out how to get it to show how many times to has been pushed!! Can someone please help!!
2 -Write a program that display two buttons, OK and Cancel, in a frame. A message is display on the console to indicate which button is clicked and how many time was each button clicked and how many time were both button clicked.
import javax.swing.*; import java.awt.event.*; public class Ok_Cancel_Button extends JFrame { public Ok_Cancel_Button() { JButton Ok = new JButton("OK"); JButton Cancel = new JButton("Cancel"); JPanel panel = new JPanel(); panel.add(Ok); panel.add(Cancel); add(panel); ListenerClass listener = new ListenerClass(); Ok.addActionListener(listener); Cancel.addActionListener(listener); } public static void main (String[] args) { JFrame frame = new Ok_Cancel_Button(); frame.setTitle ("Ok/Canel Buttons"); frame.setSize (500, 500); frame.setLocation(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } } class ListenerClass implements ActionListener { public void actionPerformed (ActionEvent e) { System.out.println ("The " + e.getActionCommand() + " button was clicked "); } }