• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • 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
 
Don't listen to Steve. Just read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic