日期:2014-05-20  浏览次数:20746 次

求帮助牛人
/**
 * 音乐播放器 
 * @author kevin
 *
 */
import java.awt.*; 
import java.net.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
//引入包

class AudioClipWindow extends Frame implements Runnable,ActionListener,ItemListener
//建立播放器的窗口,继承FRAME,引入多线程,接收项事件的侦听器接口,接收项事件的侦听器接口
{
Thread thread;//定义线程
Choice choice;
URL url;
AudioClip Clip;
Button buttonPlay,buttonLoop,buttonStop;
String str;

AudioClipWindow()
{
thread=new Thread(this);
choice=new Choice();
choice.add("陈奕迅 - 浮夸_2011926211651.wav");
choice.add("陈奕迅 - 打回原形(1)_2011926212236.wav");
choice.addItemListener(this);
buttonPlay=new Button("播放");
buttonLoop=new Button("循环");
buttonStop=new Button("停止");
buttonPlay.addActionListener(this);
buttonStop.addActionListener(this);
buttonLoop.addActionListener(this);
setLayout(new FlowLayout());
add(choice);
add(buttonPlay);
add(buttonLoop);
add(buttonStop);
setSize(500,120);
setVisible(true);
setTitle("EASON播发器");
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
validate();//确保组件具有有效的布局
}



public void itemStateChanged(ItemEvent e)
{
str=choice.getSelectedItem();
if(!(thread.isAlive()))
{
thread=new Thread(this);

}
try{
thread.start();
}
catch(Exception ee)
{

}
}
public void run()
{
try{
File file=new File(str);
url=file.toURL();
Clip=Applet.newAudioClip(url);
}
catch(Exception e)
{
System.out.println(e);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==buttonPlay)
{
Clip.play();
}
else if(e.getSource()==buttonLoop)
{
Clip.loop();

}
else if(e.getSource()==buttonStop)
{
Clip.stop();
}
}


public static class Demo3 
{

public static void main(String args[]) 
{
// TODO Auto-generated method stub
AudioClipWindow win=new AudioClipWindow();

}

}
}
为什么我放不出音乐啊

------解决方案--------------------
Clip.play(); Clip是null