Play Beep Sound in Java
Submitted by donbermoy on Saturday, May 3, 2014 - 20:49.
In this tutorial, i will teach you how to create a program that can play beep sound in java.
Now, let's start this tutorial!
1. Name your java program as beep.java.
2. Import the following packages below.
We will just use the awt.Toolkit for this tutorial to access
3. Initialize your button. Named it as btnok.
4. Put this code for your Main. This is to set the size and location of your form to be displayed.
5. Create a method named beep(). This will add a panel to your form, set color for the background, call the ActionListener for our button, and will set the location of your button in the panel.
6. Add the button's action listener so that it will trigger to play the beep sound when clicked.
Toolkit.getDefaultToolkit().beep() syntax is the event class of all beep sound implementations of the Abstract Windowing Toolkit. This Toolkit class are used to bind the various components to particular native toolkit implementations. This is why we just call the beep() method inside the toolkit class of awt or Abstract Windowing Toolkit.
Output:
Here's the full code of this tutorial:
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- Login p1= new Login();
- p1.setSize(250,140);
- p1.setLocation(300,300);
- p1.setVisible(true);
- p1.setResizable(false);
- }
- public beep() {
- super("Play Beep Sound");
- pane.setLayout(null);
- pane.add(btnok);
- btnok.setBounds(75,50,100,76);
- btnok.addActionListener(this);
- btnok.setToolTipText("Beep Sound");
- setContentPane(pane);
- }
- if(source==btnok)
- {
- }
- else
- {
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- Login p1= new Login();
- p1.setSize(250,140);
- p1.setLocation(300,300);
- p1.setVisible(true);
- p1.setResizable(false);
- }
- public beep() {
- super("Play Beep Sound");
- pane.setLayout(null);
- pane.add(btnok);
- btnok.setBounds(75,50,100,76);
- btnok.addActionListener(this);
- btnok.setToolTipText("Beep Sound");
- setContentPane(pane);
- }
- if(source==btnok)
- {
- }
- else
- {
- }
- }
- }
Add new comment
- 1618 views