Reputation: 1
How do you add sounds effects to radio Buttons in Java GUI? For example the click sounds when clicking the radio Buttons. Please tell me and explain how.
I didn't try or copied all of those examples and explanations in YouTube years ago are cause they're somewhat Vague and not really exaggerated I just really want to know how. I just wanna know what are the basics. Please do Share. Thank you.
Upvotes: 0
Views: 159
Reputation: 79
Its been a while since I did this. I would say in your action handler that is where you want to get your sound and then play it. So somthing like this:
JButton b1 = new JButton("Cool button"); // Make button
// Create action listener - play the sound when the button is pressed
ActionListener listener = new ActionListener() {
File localSoundFile = new File("path_to_sound");
AudioInputStream audioIn = AudioSystem.getAudioInputStream(localSoundFile);
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
// Other action handler stuff
}
b1.addActionListener(listener); // Attatch listener to the button
Change the code to work with whatever gui framwork you are using, but the overall design should be something similar
Upvotes: 1