469,282 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Playing beep sound on J2SE

539 512MB
Is there a way to play the alert tone(small speaker) installed on the motherboard from java?

Like the way we call it in C "\a" character........ i forgot whats the code to play it in C.... im not sure......
Aug 25 '08 #1
10 8849
myusernotyours
188 100+
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. public class beep {
  3.   public static void main(String args[]) {
  4.      Toolkit.getDefaultToolkit().beep();
  5.      }
  6.   }
  7.  
  8. }
Regards
Alex.
Aug 25 '08 #2
sukatoa
539 512MB
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. public class beep {
  3.   public static void main(String args[]) {
  4.      Toolkit.getDefaultToolkit().beep();
  5.      }
  6.   }
  7.  
  8. }
Regards
Alex.
Thanks for your reply........ That also beeps.......

But the beep that i was trying to play is from that speaker:

Installed in the Motherboard,
Cylindrical form (less than an inch diameter, half an inch height) speaker...
Near the rechargeable(Lithium/Nickel) battery above the RAM port, or similar....

Not the external(connected in audio port)....

For example, when we unplug the harddisk(Get out from IDE/SATA), then start the PC, that beep(Morse type) signifies that a required harddrive must be plugged-in.....

Another example is from the mysql command-prompt.... that when we got the wrong query, that speaker also beeps......

But, anyway thanks for your reply......
sukatoa
Aug 25 '08 #3
Nepomuk
3,112 Expert 2GB
To beep with the mainboard speaker, use this:
Expand|Select|Wrap|Line Numbers
  1. System.out.println("\007");
  2. System.out.flush();
However, this might not work within an IDE like Eclipse - it will however work when calling your program from command line.

Greetings,
Nepomuk
Aug 25 '08 #4
myusernotyours
188 100+
Any one Knows why this does not work with an IDE? Even in netbeans no beep sounds. And I also found that a SplashScreen does not work in an IDE either. Makes one feel shortchanged if an IDE can't support such 'simple' stuff.
Aug 25 '08 #5
Nepomuk
3,112 Expert 2GB
Any one Knows why this does not work with an IDE? Even in netbeans no beep sounds. And I also found that a SplashScreen does not work in an IDE either. Makes one feel shortchanged if an IDE can't support such 'simple' stuff.
I don't know about the SplashScreens, but the beep sound is not played because the standard output goes to the IDE instead of "normal" stdio and is not forwarded from there. You could probably make it beep by writing a simple C program like
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main()
  3. {
  4.    printf("\a");
  5. }
and calling that from Java. Not a nice way to do it, I admit, but it should work. Or course, this C file would have to be recompiled for every platform you use it on, but if it's just for developement...

By the way, you can use
Expand|Select|Wrap|Line Numbers
  1. System.out.println('\b');
too - it does the same as System.out.println('\007').

Probably the best option is just to test your program with the command line ever so often, to make sure all of the beeps are at the right place.

Greetings,
Nepomuk
Aug 25 '08 #6
sukatoa
539 512MB
Thanks for replies guys.....

Can i request to admin?

To change the title into "Playing beep sound on J2SE" or near to this topic?

Alert tone sounds like J2ME......

I've attempted searching about this topic, and all i've got is a sample for J2ME.....


Thanks again,
sukatoa
Aug 25 '08 #7
r035198x
13,262 8TB
...

Can i request to admin?

To change the title into "Playing beep sound on J2SE" or near to this topic?

..
That will be two nickels ...
Aug 25 '08 #8
JosAH
11,448 Expert 8TB
Any one Knows why this does not work with an IDE? Even in netbeans no beep sounds. And I also found that a SplashScreen does not work in an IDE either. Makes one feel shortchanged if an IDE can't support such 'simple' stuff.
It all depends on the terminal (emulation) capabilities; there are a lot of Unicode
ISO control characters; I never see any bold (or stretched out) font characters
following an SO character either. Look here for all of them; most are forgotten.

kind regards,

Jos
Aug 25 '08 #9
BigDaddyLH
1,216 Expert 1GB
I hate it when programs beep.
Aug 25 '08 #10
JosAH
11,448 Expert 8TB
I hate it when programs beep.
Especially for you I am going to play Ludwig von Beethoven's Symphony #9
for an irritating little computer beep thingy:

an'a one, an'a two, an'a one, two, three four! Maestro!

<beep><beep>><bip><boooooop>
<baap><baap><bep>>booooooooop>
<bip><bip><bip><bip><bip><bip><bip><bip><bwooop>
<bip><bip><bip><bip><bip><bip><bip><bip><bip><bwaa aaap>
<da capo al fine/>

kind regards,

Jos ;-)
Aug 25 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Kiteman \(Canada\) | last post: by
reply views Thread by Put 030516 in email subj to get thru | last post: by
2 posts views Thread by bill_m | last post: by
5 posts views Thread by Ike | last post: by
3 posts views Thread by Thom Little | last post: by
4 posts views Thread by Ross | last post: by
4 posts views Thread by =?Utf-8?B?UmljaA==?= | last post: by
6 posts views Thread by =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.