Reputation: 11
I'm very beginner in Java, so ...
I've written a simple Java code to display images from my hard drive wherever I click the mouse, not on the applet, on panel, now how can I make a sound play automatically when I view 6 pictures ?
public void mouseClicked(MouseEvent e) {
if (count == images.length - 1) {
???????????????????????
} else {
count++;
}
x = e.getX();
y = e.getY();
frameTest.repaint();
}
I want to play a sound file from the Hard drive, in the place of question marks ..
can some one help plz ?
Upvotes: 1
Views: 1237
Reputation: 591
Try to write this inside your if :
try
{
Clip clickClip = AudioSystem.getClip();
URL clipURL = new URL("file://C:/aFile.wav");
AudioInputStream ais = AudioSystem.getAudioInputStream(clipURL);
clickClip.open(ais);
clickClip.start();
}
catch(Exception e)
{
System.out.ptintln("Something didn't work !\n" + e.printStackTrace());
}
Hope this helps.
Upvotes: 1