Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.samkough.main;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- @SuppressWarnings("serial")
- public class Win extends JFrame implements ActionListener
- {
- private static final int WIDTH = 600;
- private static final int HEIGHT = 150;
- JButton b1;
- JLabel l1;
- int counter = 0, x = 0;
- String s;
- public Win()
- {
- setLayout(new FlowLayout());
- b1 = new JButton("Click for sound");
- l1 = new JLabel("");
- add(b1);
- add(l1);
- b1.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e)
- {
- // this is the beep sound
- getToolkit().getDefaultToolkit().beep();
- counter++;
- if (x == 0)
- {
- s = "time";
- }
- else if (x == 1)
- {
- s = "times";
- }
- l1.setText("You have clicked " + counter + " " + s + ".");
- x = 1;
- }
- public static void main(String args[])
- {
- Win frame = new Win();
- frame.setVisible(true);
- frame.setSize(WIDTH, HEIGHT);
- frame.setTitle("Beeper");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement