Computer Science 252
 Problem Solving with Java
Fall 2015, The College of Saint Rose
AudioClipDemo Demo
A working demo of AudioClipDemo will appear below. Click inside the applet to interact with it.
AudioClipDemo BlueJ Project
Click here to download a BlueJ project for AudioClipDemo.
AudioClipDemo Source Code
The Java source code for AudioClipDemo is below. Click on a file name to download it.
import objectdraw.*;
import java.awt.*;
import java.applet.*;
/*
 * Example AudioClipDemo: show how to play audio clips
 *
 * Jim Teresco, The College of Saint Rose, CSC 252, Fall 2014
 *
 * $Id: AudioClipDemo.java 2455 2014-10-14 16:17:33Z terescoj $
 */
public class AudioClipDemo extends WindowController {
    private VisibleImage ella;
    
    // we can store a playable audio clip in an AudioClip object
    private AudioClip barkSound;
    
    public void begin() {
        
        ella = new VisibleImage(getImage("ella.jpg"), 10, 10, canvas);
        
        // we can convert an audio file to an AudioClip with getAudio
        barkSound = getAudio("dogbark4.wav");
    }
    
    public void onMousePress(Location point) {
        
        if (ella.contains(point)) {
            // if we have a valid AudioClip, its play method can be used to play it
            barkSound.play();
        }
    }
    
}