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);  }}
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: