开发者

Display image and play audio clip in applet

I want to display image in开发者_如何学Python an applet and play audio clip. I wrote the following code but its not working. I have written code just for image but dont have any idea for audio clip. Please let me know where I am making mistake..

import java.applet.*;
import java.awt.*;
import java.net.*;
/*
<applet code="Showimage" width = 400 height = 400>
</applet>
*/
public class Showimage extends Applet
{
URL codb;
Image picture;
public void init()
{
    codb = getCodeBase();
    picture = getImage(codb, "Choti.jpg");
}
public String getAppletInfo()
{
    return "Hi...";
}
public void start() {   }
public void paint(Graphics g)
{
    g.drawImage(picture, 10, 10, this);
    showStatus(getAppletInfo());
}
}


import java.applet.*;
import java.awt.*;
import java.net.*;
/*
<applet code="Showimage" width = 400 height = 400>
</applet>
*/
public class Showimage extends Applet
{
    URL codb;
    Image picture;
    AudioClip clip;

    public void init()
    {
        picture = getImage(getCodeBase(), "../images/Beagle.jpg");

        clip  = getAudioClip(getDocumentBase(), "sound/woof.wav");
    }

    public String getAppletInfo()
    {
        return "Hi...";
    }

    public void start() { 
        clip.play();
        showStatus(getAppletInfo());
    }

    public void paint(Graphics g)
    {
        g.drawImage(picture, 10, 10, this);
    }
}

Would find the image & sound with this directory structure.

  • images
    • Beagle.jpg
  • applet
    1. sound
      • woof.wav
    2. applet.html


An applet class and image "Choti.jpg" must be in same folder.

Use getImage(java.net.URL) method to get an image from other location/folder and use play(URL,string) or play(URL) method to play audio clip. For more detail visit applet tutorial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜