Hello, If you want to make use of the code which will provide you different audio clips then you can simply make use of the code below and get your problem solved:
Code:
import java.applet.*;
import java.awt.*;
import java.util.Random;
public class AudCheck extends Applet implements Runnable
{
AudioClip audioC[] = new AudioClip[8];
Thread thrd;
Random rand = new Random(System.currentTimeMillis());
public void init()
{
audioC[0] = getAudioClip(getDocumentBase(), "Hillbilly.au");
audioC[1] = getAudioClip(getDocumentBase(), "Cow.au");
audioC[2] = getAudioClip(getDocumentBase(), "Duck.au");
audioC[3] = getAudioClip(getDocumentBase(), "Goat.au");
audioC[4] = getAudioClip(getDocumentBase(), "Hen.au");
audioC[5] = getAudioClip(getDocumentBase(), "Horse.au");
audioC[6] = getAudioClip(getDocumentBase(), "Pig.au");
audioC[7] = getAudioClip(getDocumentBase(), "Rooster.au");
}
public void start()
{
if (thrd == null)
{
thrd = new Thread(this);
thrd.start();
}
}
public void stop()
{
if (thrd != null)
{
thrd.stop();
thrd = null;
}
}
public void run()
{
while (Thread.currentThread() == thrd)
{
audioC[0].loop();
while (true)
{
try
Thread.sleep(3000);
catch (InterruptedException e)
break;
audioC[(rand.nextInt() % 3) + 4].play();
}
}
}
public void paint(Graphics g)
{
Font fnt = new Font("TimesRoman", Font.PLAIN, 20);
FontMetrics fontmetrics = g.getFontMetrics(fnt);
String str = new String("Testing");
g.setFont(fnt);
g.drawString(str, (size().width - fontmetrics.stringWidth(str)) / 2,
((size().height - fontmetrics.getHeight()) / 2) + fontmetrics.getAscent());
}
}
Bookmarks