标题:[求助]我的程序不能播放声音请帮帮小弟
只看楼主
fflyingg
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-9-22
 问题点数:0 回复次数:0 
[求助]我的程序不能播放声音请帮帮小弟

能通过编译,但点播放后就是没声音出来
import java.net.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.*;
//播放音频片断的实例
public class SoundTest extends JFrame implements ActionListener{
private JButton playMusic=new JButton("Play Music");
private JButton loopMusic=new JButton("Loop Music");
private JButton stopMusic=new JButton("stop Music");
private JButton playSound=new JButton("Play Sound");
private JButton stopSound=new JButton("Stop Sound");
private AudioClip music=null,sound=null;
public SoundTest(){
super("Sound Test");
try{
String separator=System.getProperty("file.separator");
String preface="file:"+System.getProperty("user.dir")+separator+"Audio"+separator;
music=Applet.newAudioClip(new URL(preface+"music.mid"));
sound=Applet.newAudioClip(new URL(preface+"applause.mid"));
}
catch(MalformedURLException murle){
System.err.println("Error loading files:"+murle);
}
Container content=getContentPane();
content.setLayout(new FlowLayout());
content.add(playMusic);playMusic.addActionListener(this);
content.add(loopMusic);loopMusic.addActionListener(this);
content.add(stopMusic);stopMusic.addActionListener(this);
content.add(playSound);playSound.addActionListener(this);
content.add(stopSound);stopSound.addActionListener(this);
validate();pack();setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==playMusic)
music.play();
else if(ae.getSource()==loopMusic)
music.loop();
else if(ae.getSource()==stopMusic)
music.stop();
else if(ae.getSource()==playSound)
sound.play();
else if(ae.getSource()==stopSound)
sound.stop();
}
public static void main(String args[]){
SoundTest st=new SoundTest();
}

}

搜索更多相关主题的帖子: import JButton java awt 
2007-10-23 19:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-180179-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.310624 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved