Beeping the System SpeakerHow 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." |