final AudioClip sound=getAudioClip(getDocumentBase(),"alarm.wav");  //取得声音文件
                                        sound.play();
我把那个音频放在这个程序的文件夹里,但播不了声音,我做的是小闹钟。请指教,谢谢……

解决方案 »

  1.   

    敖包到jar里面。通过class.getResource获取。
      

  2.   

    应该差不多的,你看一下JDK的DEMO
      

  3.   

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;public class PlaySoundApplet extends Applet implements ActionListener{
      Button play,stop;
      AudioClip audioClip;  public void init(){
        play = new Button("  Play in Loop  ");
        add(play);
        play.addActionListener(this);
        stop = new Button("  Stop  ");
        add(stop);
        stop.addActionListener(this);
        audioClip = getAudioClip(getCodeBase(), "TestSnd.wav");
      }
      
      public void actionPerformed(ActionEvent ae){
        Button source = (Button)ae.getSource();
        if (source.getLabel() == "  Play in Loop  "){
          audioClip.play();
        }
        else if(source.getLabel() == "  Stop  "){
          audioClip.stop();
        }
      }
    }
      

  4.   

    在这个小程序所在文件夹里放入一个WAV音频后还是无法播放。
      

  5.   

    你用
    AudioClip sound = Applet.newAudioClip(getClass().getResource("alarm.wav"));
    sound.play();
    ...
    试试看怎么样