这样一个小程序
//音乐盒,通过下拉列表来选择音乐import javax.swing.*;public class JukeBox
{
public static void main (String[] args) throws Exception
{
JFrame frame=new JFrame("JukeBox");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().add(new JukeBoxControls());

frame.pack();
frame.setVisible(true);
}
}
//控制面板import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.AudioClip;
import java.net.URL;public class JukeBoxControls extends JPanel
{
private JComboBox musicCombo;
private JButton stopButton,playButton;
private AudioClip[] music;
private AudioClip current;

public JukeBoxControls()
{
URL url1,url2,url3,url4,url5,url6,url;
url1=url2=url3=url4=url5=url6=null;

try
{
url1=new URL("file","localhost","The climb.wav");
url2=new URL("file","localhost","Burning-Maria Arredondo.wav");
url3=new URL("file","localhost","You Are Not Alone-Michael.wav");
url4=new URL("file","localhost","Love Story-Taylor Swift.wav");
url5=new URL("file","localhost","星月神话.wav");
url6=new URL("file","localhost","西城男孩 - soledad.wav");

}catch(Exception e){}

//Creats the list.
music=new AudioClip[7];
music[0]=null;
music[1]=JApplet.newAudioClip(url1);
music[2]=JApplet.newAudioClip(url2);
music[3]=JApplet.newAudioClip(url3);
music[4]=JApplet.newAudioClip(url4);
music[5]=JApplet.newAudioClip(url5);
music[6]=JApplet.newAudioClip(url6);

String[] musicNames={"Make a select...","The climb","Burning-Maria Arredondo",
"You Are Not Alone-Michael","Love Story-Taylor Swift","星月神话","西城男孩 - soledad"};

musicCombo=new JComboBox(musicNames);
musicCombo.setBackground(Color.ORANGE);

//Set up the buttons
playButton=new JButton("Play",new ImageIcon("play.jpg"));
playButton.setBackground(Color.ORANGE);
stopButton=new JButton("stop",new ImageIcon("stop.jpg"));
stopButton.setBackground(Color.ORANGE);

//set up the panel.
setPreferredSize(new Dimension(250,100));
setBackground(Color.ORANGE);
add(musicCombo);
add(playButton);
add(stopButton);

musicCombo.addActionListener(new ComboListener());
playButton.addActionListener(new ButtonListener());
stopButton.addActionListener(new ButtonListener());
current=null;

}

private class ComboListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(current!=null)
current.stop();
current=music[musicCombo.getSelectedIndex()];
}
}

private class ButtonListener implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
if(current!=null)
current.stop();
if(e.getSource()==playButton)
if(current!=null)
current.play();
}
}
}
运行时提示内存溢出,这六个音频文件供200多M,查了下,Java的默认内存不是1500M吗?当我把其中的五个去掉,只剩一个时则可以正常播放;请问怎么解决?多谢

解决方案 »

  1.   

    JVM的默认内存是很小的,楼主可以修改JVM启动的内存加载参数
      

  2.   

    java的默认内存是1500m?谁说的?我怎么记得一般是 -Xms64m -Xmx256m  最大256m啊
      

  3.   

    恩那,默认64M~~~要是1500M,如果一个PC只有一个G,那就完了~~
      

  4.   

    你可以看一下试一下
    System.out.println(Runtime.getRuntime().maxMemory()/1024/1024);
    我这儿显示是63 应该就是63m