To play sounds along with slides in the SlideShowApplet, you would make the following modifications to the code: private URL soundURL[] = new URL[NIMGS]; Declare an array of URLs to store the URLs of the audio files you want to play. Assign URLs to the array at the same time you input the images: for (int k=0; k < NIMGS; k++) { url = new URL( "http://starbase.trincoll.edu/~jjjava/slide" + k + ".gif"); slide[k] = getImage( url ); soundURL[k] = new URL("http://starbase.trincoll.edu/~jjjava/sound" + k + ".au"); } Each time an image is displayed in paint(), play the corresponding sound by using the URL from the array: public void paint(Graphics g) { if (currentImage != null) { g.drawImage(currentImage,10,10,this); play( soundURL[currentImage] ); } }
|