Generate Beeps in Your Application

Many applications use an audible “beep” sound to signal that an error has occurred or to get the user’s attention for some reason. For example, a user interface that allows the user to enter only a certain number or type of characters into a field (i.e., a field that can only contain numeric values) may “beep” whenever a user presses a key representing an invalid character or when the field is already “full.” To generate beeps in Java, you must first get a reference to an instance of java.awt.Toolkit, at which time you can call its beep() method. For example, the code shown here will generate a beep whenever the displayed Button is pressed:

 import java.awt.*;import java.awt.event.*;public class BeepTest extends Frame implements ActionListener {	public static void main(String[] args) {		BeepTest bt = new BeepTest();		bt.setSize(400, 300);		bt.setVisible(true);	}  //  public static void main(String[] args)	public BeepTest() {		setLayout(new FlowLayout());		Button b = new Button("Click To Beep");		b.addActionListener(this);		add(b);	}  //  public BeepTest()	public void actionPerformed(ActionEvent event) {		Toolkit tk = Toolkit.getDefaultToolkit();		tk.beep();	}  //  public void actionPerformed()}  //  public class BeepTest extends Frame()

In the actionPerformed() method, a reference is obtained to the default Toolkit instance, and its beep() method is called. You can use this technique to enhance your user interface with beep sounds where appropriate.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may