代码如下:
- Java code
package ex18;import javax.swing.*;import java.net.URL;import java.applet.*;public class DisplayImagePlayAudio extends JApplet{ private AudioClip audioClip; public DisplayImagePlayAudio(){ URL urlForImage = getClass().getResource("E:/学习资料/book/image/denmark.gif"); add(new JLabel(new ImageIcon(urlForImage))); URL urlForAudio = getClass().getResource("E:/学习资料/book/audio/denmark.mid"); audioClip = Applet.newAudioClip(urlForAudio); audioClip.loop(); } public void start(){ if(audioClip != null) audioClip.loop(); } public void stop(){ if(audioClip != null) audioClip.stop(); }}
我输入的路径没有错,但是每次运行都有NullPointerException
------解决方案--------------------
在applet中要访问本地资源要签名授权的。
------解决方案--------------------
内容太多,打字太累,给你一个博客地址吧
http://www.blogjava.net/nokiaguy/archive/2009/02/06/253636.html