在小程序中显示图像和播放音频片段 [英] Display image and play audio clip in applet
本文介绍了在小程序中显示图像和播放音频片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在小程序中显示图像并播放音频剪辑.我写了以下代码但它不起作用.我只为图像编写了代码,但对音频剪辑一无所知.请让我知道我哪里出错了..
I want to display image in 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.
- 图片
- 小猎犬.jpg
- 声音
- woof.wav
这篇关于在小程序中显示图像和播放音频片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文