当前位置: 代码迷 >> J2SE >> 帮忙看看,不知道哪里出了异常
  详细解决方案

帮忙看看,不知道哪里出了异常

热度:94   发布时间:2016-04-24 00:52:45.0
帮忙看看,不知道哪里出了错误
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.applet.*;

public class Player extends JApplet implements ActionListener,ListSelectionListener

{
private JButton jb1=new JButton("replay");
private JButton jb2=new JButton("play");
private JButton jb3=new JButton("stop");
private AudioClip sound;
private JList<String>list;
private int temp;
private String currentMusic=new String("haikuo.mid");
private String[] music={"someone like you.mid","make you feel my love.mid",
"don't you remember.mid","haikuo.mid"};
public Player()
{
JFrame frame=new JFrame();
frame.setSize(250,400);
frame.setLocation(new Point(100,300));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar bar=new JMenuBar();
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
frame.setJMenuBar(bar);
Container con1=frame.getContentPane();
con1.setLayout(new BorderLayout());
panel1.setLayout(new GridLayout(1,3));
panel2.setLayout(new BorderLayout());
JScrollPane jsp;
list=new JList<String>(music);
jsp=new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.setTitle("music");
bar.add(new JMenu(" "));
panel1.add(jb1);
panel1.add(jb2);
panel1.add(jb3);
panel2.add(panel1,BorderLayout.NORTH);
panel2.add(jsp,BorderLayout.CENTER);
con1.add(panel2,BorderLayout.CENTER);
jb1.addActionListener(this);
  jb2.addActionListener(this);
  jb3.addActionListener(this);
  list.addListSelectionListener(this);
  frame.setVisible(true);
}
public void valueChanged(ListSelectionEvent e)
{
temp=list.getSelectedIndex();
currentMusic=music[temp];
}
public void actionPerformed (ActionEvent e)
{
sound=getAudioClip(getDocumentBase(),currentMusic);
  if(e.getSource()==jb1)
  sound.play();
  else if(e.getSource()==jb2)
  sound.loop();
  else
  sound.stop();
}
public static void main(String[] args)
{
new Player();
}
}


------解决方案--------------------
把JList后面的<String>去掉就可以了吧
  相关解决方案