Advertisement
//Evening handling in an applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Applet12" width=400 height=350>
</applet>
*/
public class Applet12 extends Applet implements ActionListener
{
Button b1;
public void init()
{
System.out.println("initializing an applet");
System.out.println("The full path to our applet file : " + getDocumentBase()); //getDocumentBase() gives URL object
System.out.println("Directory in which our applet file is located : " + getCodeBase()); //getCodeBase() gives URL object
b1 = new Button("Play");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("Play"))
play(getDocumentBase(),"Acoustic Guitar.wav"); //playing a song(.wav format) from the same directory in which applet code file is located
}
public void paint(Graphics g)
{
g.drawString("Click on the play button to play the music", 80,80);
showStatus("Applet playing audio(.wav file)");
}
}
appletviewer Applet12.java
Advertisement
//Evening handling in an applet
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Applet13" width=400 height=350>
</applet>
*/
public class Applet13 extends Applet implements ActionListener
{
Button b1, b2, b3;
AudioClip ac;
public void init()
{
System.out.println("initializing an applet");
System.out.println("The full path to our applet file : " + getDocumentBase()); //getDocumentBase() gives URL object
System.out.println("Directory in which our applet file is located : " + getCodeBase()); //getCodeBase() gives URL object
b1 = new Button("Play");
add(b1);
b2 = new Button("Loop");
add(b2);
b3 = new Button("Stop");
add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("Play"))
{
ac = getAudioClip(getDocumentBase(),"Acoustic Guitar.wav"); //playing a song(.wav format) from the same directory in which applet code file is located
ac.play();
}
if(ae.getActionCommand().equals("Loop"))
{
ac = getAudioClip(getDocumentBase(),"Acoustic Guitar.wav"); //playing a song(.wav format) from the same directory in which applet code file is located
ac.loop();
}
if(ae.getActionCommand().equals("Stop"))
{
ac = getAudioClip(getDocumentBase(),"Acoustic Guitar.wav"); //playing a song(.wav format) from the same directory in which applet code file is located
ac.stop();
}
}
public void paint(Graphics g)
{
g.drawString("Click on the button to play,loop or stop the music", 80,80);
showStatus("Applet playing audio(.wav file)");
}
}
appletviewer Applet13.java
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement