I\'m currently working on a Magic8Ball game, very basic, although I did change it to a genie theme, and now I\'ve decided to add sound to the game.
Basically I have pre
Simple example for playing a sound:
import java.awt.event.*;
import javax.swing.*;
import javax.sound.sampled.*;
import java.net.URL;
import java.io.*;
class SoundTest {
public static void main(String[] args) throws Exception {
URL urlToSound = new URL("file:c:/java/gun1.wav");
// URL urlToSound = new URL("file:c:/java/flyby1.wav");
AudioInputStream ais = AudioSystem.getAudioInputStream(urlToSound);
final Clip clip = AudioSystem.getClip();
clip.open(ais);
JButton button = new JButton("Play Sound");
button.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent ae) {
clip.setFramePosition(0);
clip.start();
}
} );
JOptionPane.showMessageDialog(null, button);
}
}