import java.net.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.*;
public class Sound extends JFrame implements ActionListener{
private JButton playMusic=new JButton("play");
private JButton loopMusic=new JButton("loop");
private JButton stopMusic=new JButton("stop");
private JButton playSound=new JButton("play s");
private JButton stopSound=new JButton("stop s");
private AudioClip music =null,sound=null;
public Sound()
{super("Sound test");
//下面的URL定位,我的声音文件在 //F:\eclipse\eclipse\workspace\Sharkgame\soundtest\Audio
try
{String separator=System.getProperty("file.separator");//此处file该是哪个?
String preface="file:"+System.getProperty("soundtest.dir")//此处的file又是哪个?+separator+"Autio"+separator;
music=Applet.newAudioClip(new URL(preface+"s.wav"));
sound=Applet.newAudioClip(new URL(preface+"v.wav"));
}
catch(MalformedURLException murle)
{System.err.println("Error loading files"+murle);}
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.add(playMusic);playMusic.addActionListener(this);
c.add(loopMusic);loopMusic.addActionListener(this);
c.add(stopMusic);stopMusic.addActionListener(this);
c.add(playSound);playSound.addActionListener(this);
c.add(stopSound);stopSound.addActionListener(this);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==playMusic)
music.play();
else if(e.getSource()==loopMusic)
music.loop();
else if(e.getSource()==stopMusic)
music.stop();
else if(e.getSource()==playSound)
sound.play();
else if(e.getSource()==stopSound)
sound.stop();
}
public static void main(String args[])
{Sound st=new Sound();}
}
我是菜鸟。。帮帮忙。。
import java.applet.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.*;
public class Sound extends JFrame implements ActionListener{
private JButton playMusic=new JButton("play");
private JButton loopMusic=new JButton("loop");
private JButton stopMusic=new JButton("stop");
private JButton playSound=new JButton("play s");
private JButton stopSound=new JButton("stop s");
private AudioClip music =null,sound=null;
public Sound()
{super("Sound test");
//下面的URL定位,我的声音文件在 //F:\eclipse\eclipse\workspace\Sharkgame\soundtest\Audio
try
{String separator=System.getProperty("file.separator");//此处file该是哪个?
String preface="file:"+System.getProperty("soundtest.dir")//此处的file又是哪个?+separator+"Autio"+separator;
music=Applet.newAudioClip(new URL(preface+"s.wav"));
sound=Applet.newAudioClip(new URL(preface+"v.wav"));
}
catch(MalformedURLException murle)
{System.err.println("Error loading files"+murle);}
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.add(playMusic);playMusic.addActionListener(this);
c.add(loopMusic);loopMusic.addActionListener(this);
c.add(stopMusic);stopMusic.addActionListener(this);
c.add(playSound);playSound.addActionListener(this);
c.add(stopSound);stopSound.addActionListener(this);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==playMusic)
music.play();
else if(e.getSource()==loopMusic)
music.loop();
else if(e.getSource()==stopMusic)
music.stop();
else if(e.getSource()==playSound)
sound.play();
else if(e.getSource()==stopSound)
sound.stop();
}
public static void main(String args[])
{Sound st=new Sound();}
}
我是菜鸟。。帮帮忙。。
就是URL不知道怎么写。
我在上面的注释里面已写好了。。
要不帮我把上面的URL部分具体写清楚。我作参考。。
我把我的声音文件的URL写出来了的。。