简体   繁体   中英

Play beep sound or any customized sound on all mouse click event in java

I have an application which i am going to install on Linux touch system. The touch system is not giving me the touch sound so i decided to have that feature on my application. What is the best way to do it ? I dont want to go through each and every buttons and other components and write the codes there. Is there any global way to handle that so that the sound works throughout the application when ever the screen is touched or mouse is clicked ??

Try this

Toolkit.getDefaultToolkit().beep();

To play it in all MouseEvent make your MouseEvent listener single and everytime when you need use that listener and write above code in that mouse listener.

Take this answer: How can I play sound in Java?

... and trigger the playback in the mouse click event.

Assuming that you are using the JFC/Swing toolkit, you might want to read a bit about using the Multiplexing Look & Feel . Even though I don't know of any ready-to-use auxiliary look and feel(s) that might fit your needs, it should be possible to write your own auxiliary look and feel which behaves as you describe above ...

... after you have created your own auxiliary look and feel make sure to start your java interpreter with the "-Dswing.auxiliarylaf=your.auxiliary.look.and.feel.Classname" parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM