| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 496 人关注过本帖
标题:[求助]我的程序不能播放声音请帮帮小弟
只看楼主 加入收藏
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
快速回复:[求助]我的程序不能播放声音请帮帮小弟
数据加载中...
 
   



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

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