import java.awt.*;
import java.applet.*
public class PlaySoundAndMusic extends Applet{
Image Buffer;
Graphics gBuffer;
AudioClip clip;
AudioClip clip2;
AudioClip clip3;
AudioClip clip4;
public void init(){
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
try
{
clip=getAudioClip(getCodeBase(),"gong.wav");
clip2=getAudioClip(getCodeBase(),"shoot.wav");
clip3=getAudioClip(getCodeBase(), "bsg.mid");
clip4=getAudioClip(getCodeBase(), "drwhotheme.mid");
}
catch (Exception e){}
}
public boolean keyDown(Event e, int key){
if(key=='1')
clip.play();
if(key=='2')
clip2.play();
if(key=='3')
clip3.play();
if(key=='4')
clip4.play();
repaint();
return true;
}
public void draw()
{
gBuffer.setColor(Color.WHITE);
gBuffer.fillRect(0,0,size().width,size().height);
gBuffer.setFont(new Font("Arial",Font.PLAIN,14));
gBuffer.setColor(Color.RED);
//if we want to use "" inside a string, we have to mask it with \!
gBuffer.drawString ("Press numeric key ‘1’ to play gong.wav,",50,30);
gBuffer.drawString ("Press numeric key '2' to play shoot.wav,",45,50);
gBuffer.drawString ("Press numberic key '3' to play bsg.mid," , 40,70);
gBuffer.drawString ("Press numberic key '4' to play drwhotheme.mid,", 35,90);
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
draw();
g.drawImage (Buffer,0,0, this);
}
}