devxlogo

Generating Beep

Generating Beep

Question:
I want to alert the user of my application withan ASCII 7 bell character. When I run the application from a prompt and use System.out.println((char)7) I get the result I am after. However, when I use jrew.exe to eliminatethe command prompt window this method no longerworks. Whats the solution for using jrew.exe andprocessing an ASCII 7 character?

Answer:
Emitting a beep such as that generated by the ASCII bell character isa platform dependent issue. Not every platform supports the notionof a command line shell with standard output where an ASCII bellcharacter can be turned into an audible sound. Therefore thedesigners of Java allowed the generation of a beep through thejava.awt.Toolkit class which provides the interface to systemdependent features through which the AWT is implemented. The Toolkitclass possesses a method called beep() which can be used to soundan alert bell as demonstrated by the following simple example:

import java.awt.*;public final class Beep {  public static final void main(String[] args) {    Toolkit.getDefaultToolkit().beep();    System.exit(0);  }}
See also  Does It Make Sense to Splurge on a Laptop?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist