dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java Language
Expertise: Beginner
Dec 23, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Generating Beep

Question:
I want to alert the user of my application with an 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 eliminate the command prompt window this method no longer works. Whats the solution for using jrew.exe and processing an ASCII 7 character?

Answer:
Emitting a beep such as that generated by the ASCII bell character is a platform dependent issue. Not every platform supports the notion of a command line shell with standard output where an ASCII bell character can be turned into an audible sound. Therefore the designers of Java allowed the generation of a beep through the java.awt.Toolkit class which provides the interface to system dependent features through which the AWT is implemented. The Toolkit class possesses a method called beep() which can be used to sound an 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);
  }
}
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date