play sound 'wav file' with AudioClip : WAV Sound « Development « Java Tutorial






import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URL;

import javax.swing.JFrame;

public class MainClass extends JFrame {
  AudioClip click;

  public static void main(String[] args) {
    new MainClass();
  }

  public MainClass() {
    this.setSize(400, 400);
    this.setTitle("Mouse Clicker");
    this.addMouseListener(new Clicker());

    URL urlClick = MainClass.class.getResource("hit.wav");
    click = Applet.newAudioClip(urlClick);

    this.setVisible(true);
  }

  private class Clicker extends MouseAdapter {
    public void mouseClicked(MouseEvent e) {
      click.play();
    }
  }
}








6.49.WAV Sound
6.49.1.play sound 'wav file' with AudioClip
6.49.2.Play sound with AudioInputStream