Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Beep sound - How to generate?

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to write a program that reminds me that I spent too much time at the Ranch! with a beep sound. Anyone knows how to generate a beep sound?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup. Look up "beep()" in the index of the Java API.

[This message has been edited by Jim Yingst (edited March 12, 2001).]
 
Sri Bala
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,
Thanks for that lead. beep() is an abstract method of Toolkit. So creating an instance of Toolkit didn't work and I figured out how to get an instance of the Toolkit and then got my program to beep. The problem now is that after beeping, the program is stuck and doesn't return. I have to break it. Seems like it's waiting for some event. Keystroke doesn't help. What's Toolkit and how does it work?
import java.awt.*;
public class Beep
{
public static void main(String args[])
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.beep();
}
}
 
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the ASCII characters is actually a beep. I believe its number 7 and if you set char c = 7 and print c, it should beep.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I get the same problem with it hanging when I use beep(), but printing 7 works OK.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this handy bit of reference right in the java tutorial.
The page is:
java.sun.com/docs/books/tutorial/essential/threads/timer.html
and it has some sample code doing exactly what you are trying to get at.
Happy Trails!
Paul
reply
    Bookmark Topic Watch Topic
  • New Topic