Java - Explain how to play sound in an applet

Explain how to play sound in an applet

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Audio1Applet extends Applet implements ActionListener
{
   Button play,stop;
   AudioClip audioClip;
   public void init()
   {
       play = new Button(" Play ");
       add(play);
       play.addActionListener(this);
       stop = new Button(" Stop ");
       add(stop);
       stop.addActionListener(this);
       audioClip = getAudioClip(getCodeBase(), "abc.wav");
   }

public void actionPerformed(ActionEvent ae)
{
   Button source = (Button)ae.getSource();
   if (source.getLabel() == " Play ")
   {
       audioClip.play();
   }
   else if(source.getLabel() == " Stop ")
   {
       audioClip.stop();
   }
}
}

<APPLET CODE="Audio1Applet" WIDTH="100" HEIGHT= "100"></APPLET>< H5>
Java - Explain how to play audio in a stand alone application
How to play audio in a stand alone application...
Java - What is the difference between an Applet and an Application?
Difference between an Applet and an Application - An applet runs with the control of a browser, where as an application runs standalone...
What are the component and container classes?
Component and container classes - A component is a graphical object. A few examples of components are: Button, Canvas, Checkbox...
Post your comment