一下java 播放音乐的程序为何不能播放源程序中指定的音乐文件?
packageprojava;importjava.awt.*;importjava.awt.event.*;importjava.applet.*;publicclas...
package projava;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class musicplay1 extends Applet{
AudioClip mymusic;
//声明按钮
Button b1,b2,b3;
public void init(){
this.setLayout(null);
b1=new Button("play");
b1.setBounds(15,20,65,25);
//为b1注册事件监听器
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//播放一次
mymusic.play();
}
});
//添加b1到窗口
this.add(b1);
b2=new Button("loop");
b2.setBounds(85,20,65,25);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mymusic.loop();
}
});
//添加b2到窗口
this.add(b2);
b3=new Button("stop");
b3.setBounds(155,20,65,25);
//为b3注册事件监听器
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mymusic.stop();
}
});
//添加b3到窗口
this.add(b3);
//设置背景颜色为粉红色
this.setBackground(new Color(255,193,255));
this.setVisible(true);
}
public void start(){
//设置播放文件
mymusic=this.getAudioClip(this.getCodeBase(),"周定纬 - 预感.wav");
mymusic.play();//默认为播放一次
}
public void stop(){
mymusic.stop();
}
public static void main(String []args){
new musicplay1();
}
} 展开
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class musicplay1 extends Applet{
AudioClip mymusic;
//声明按钮
Button b1,b2,b3;
public void init(){
this.setLayout(null);
b1=new Button("play");
b1.setBounds(15,20,65,25);
//为b1注册事件监听器
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//播放一次
mymusic.play();
}
});
//添加b1到窗口
this.add(b1);
b2=new Button("loop");
b2.setBounds(85,20,65,25);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mymusic.loop();
}
});
//添加b2到窗口
this.add(b2);
b3=new Button("stop");
b3.setBounds(155,20,65,25);
//为b3注册事件监听器
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
mymusic.stop();
}
});
//添加b3到窗口
this.add(b3);
//设置背景颜色为粉红色
this.setBackground(new Color(255,193,255));
this.setVisible(true);
}
public void start(){
//设置播放文件
mymusic=this.getAudioClip(this.getCodeBase(),"周定纬 - 预感.wav");
mymusic.play();//默认为播放一次
}
public void stop(){
mymusic.stop();
}
public static void main(String []args){
new musicplay1();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询