急 ,java 做的音乐播放器 高手来帮忙下!!在线等?
importjava.awt.*;importjava.awt.event.*;importjava.applet.Applet;importjava.applet.Au...
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.applet.AudioClip;
public class Music extends Applet implements ItemListener
{
/**
*
*/
AudioClip[] midi = new AudioClip[3];
AudioClip song;
Choice coi=new Choice();
Button bnt_loop=new Button("循环");
Button bnt_stop=new Button("停止");
public void init()
{
String num;
for(int i=0;i<midi.length;i++);
{
int i = 0;
num=String.valueOf(i+1);
midi[i]=getAudioClip(getCodeBase(),num+".mid");
}
coi.add("分手在那个秋天");coi.add("倔强");coi.add("光荣");
add(coi);
add(bnt_loop);add(bnt_stop);
coi.addItemListener(this);
bnt_loop.addActionListener(new MyActLit());
bnt_stop.addActionListener(new MyActLit());
song=midi[0];
song.play();
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public void itemStateChanged(ItemEvent e)
{
song.stop();
int i=coi.getSelectedIndex();
song=midi[i];
song.play();
// TODO Auto-generated method stub
}
class MyActLit implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Button bnt = (Button) e.getSource();
if (bnt==bnt_loop) song.loop();
else song.stop();
}
}
怎样添加音乐,是复制到.class下么,为什么我的能运行成功,但不能播放音乐,运行显示的是:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at Music.itemStateChanged(Music.java:44)
at java.awt.Choice.processItemEvent(Unknown Source)
at java.awt.Choice.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)显示的是 展开
import java.awt.event.*;
import java.applet.Applet;
import java.applet.AudioClip;
public class Music extends Applet implements ItemListener
{
/**
*
*/
AudioClip[] midi = new AudioClip[3];
AudioClip song;
Choice coi=new Choice();
Button bnt_loop=new Button("循环");
Button bnt_stop=new Button("停止");
public void init()
{
String num;
for(int i=0;i<midi.length;i++);
{
int i = 0;
num=String.valueOf(i+1);
midi[i]=getAudioClip(getCodeBase(),num+".mid");
}
coi.add("分手在那个秋天");coi.add("倔强");coi.add("光荣");
add(coi);
add(bnt_loop);add(bnt_stop);
coi.addItemListener(this);
bnt_loop.addActionListener(new MyActLit());
bnt_stop.addActionListener(new MyActLit());
song=midi[0];
song.play();
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public void itemStateChanged(ItemEvent e)
{
song.stop();
int i=coi.getSelectedIndex();
song=midi[i];
song.play();
// TODO Auto-generated method stub
}
class MyActLit implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Button bnt = (Button) e.getSource();
if (bnt==bnt_loop) song.loop();
else song.stop();
}
}
怎样添加音乐,是复制到.class下么,为什么我的能运行成功,但不能播放音乐,运行显示的是:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at Music.itemStateChanged(Music.java:44)
at java.awt.Choice.processItemEvent(Unknown Source)
at java.awt.Choice.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)显示的是 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询