Troubleshooting

   

Beeping the System Speaker

How do I generate a beep from the system speaker?

The Toolkit class (located in the java.awt package) contains a beep method. You call this method to beep the system speaker, as demonstrated by the following Audio1 application.

 // Audio1.java import java.awt.*; class Audio1 {    public static void main (String [] args)    {       Toolkit tk = Toolkit.getDefaultToolkit ();       tk.beep ();       System.exit (0);    } } 

The System.exit (0) method call is needed to ensure that this application terminates. It doesn't terminate because the Toolkit.getDefaultToolkit method call results in the AWT library being loaded, and a couple of threads starting. Even though the thread executing the main method terminates, these other threads continue to run, which keeps this program " alive ." System.exit kills all threads, allows the application to "die."

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net