Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- public class ButtonTester_P12_5 implements ActionListener
- {
- public static void main(String[] args)
- {
- JFrame frame = new JFrame();
- JButton button = new JButton("Button A");
- ActionListener listener = new ButtonTester_P12_5();
- button.addActionListener(listener);
- JButton button2 = new JButton("Button B");
- frame.add(button2);
- ActionListener listener2 = new ButtonTester_P12_5();
- button2.addActionListener(listener2);
- JPanel panel = new JPanel();
- panel.add(button);
- panel.add(button2);
- frame.add(panel);
- frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- public void actionPerformed(ActionEvent event)
- {
- System.out.print("Button A was clicked ");
- System.out.print(clickCount);
- System.out.print(" times. ");
- System.out.print("Clicked at ");
- System.out.print(date);
- clickCount++;
- }
- public long getWhen(ActionEvent event)
- {
- }
- private int clickCount = 1;
- private String date;
- private static final int FRAME_WIDTH = 100;
- private static final int FRAME_HEIGHT = 110;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement