This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 15th, 2012  |  syntax: None  |  size: 1.46 KB  |  views: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.event.ActionListener;
  2. import java.awt.event.ActionEvent;
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6.  
  7. public class ButtonTester_P12_5 implements ActionListener
  8. {  
  9.     public static void main(String[] args)
  10.     {  
  11.         JFrame frame = new JFrame();
  12.         JButton button = new JButton("Button A");
  13.  
  14.         ActionListener listener = new ButtonTester_P12_5();
  15.         button.addActionListener(listener);
  16.  
  17.         JButton button2 = new JButton("Button B");
  18.         frame.add(button2);
  19.  
  20.         ActionListener listener2 = new ButtonTester_P12_5();
  21.         button2.addActionListener(listener2);
  22.  
  23.         JPanel panel = new JPanel();
  24.         panel.add(button);
  25.         panel.add(button2);
  26.         frame.add(panel);
  27.  
  28.         frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
  29.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         frame.setVisible(true);
  31.     }
  32.  
  33.     public void actionPerformed(ActionEvent event)
  34.     {
  35.         System.out.print("Button A was clicked ");
  36.         System.out.print(clickCount);
  37.         System.out.print(" times. ");
  38.        
  39.         System.out.print("Clicked at ");
  40.         System.out.print(date);
  41.  
  42.         clickCount++;
  43.     }
  44.  
  45.     public long getWhen(ActionEvent event)
  46.     {
  47.  
  48.     }
  49.    
  50.     private int clickCount = 1;
  51.     private String date;
  52.    
  53.     private static final int FRAME_WIDTH = 100;
  54.     private static final int FRAME_HEIGHT = 110;
  55. }
clone this paste RAW Paste Data