这样一个小程序
//音乐盒,通过下拉列表来选择音乐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吗?当我把其中的五个去掉,只剩一个时则可以正常播放;请问怎么解决?多谢
//音乐盒,通过下拉列表来选择音乐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吗?当我把其中的五个去掉,只剩一个时则可以正常播放;请问怎么解决?多谢
解决方案 »
- 求助:如何让SWT的FileDialog禁止手动输入文件名
- 求我的聊天室客户端异常退出的处理办法!
- 应用程序中最小化图标的问题
- spring多线程访问问题,跪求答案
- tomcat 怎么样配置象www.zz.ha.cn的名字 不用在写IP地址加文件名了 就是解析IP地址 急盼
- 求助:如何替换“[]”字符?
- MD5码用什么工具可以验证?
- 有谁知道微软的project网络版的吗,或者类似于project网络版的工具?.
- read hat 7.1,tomcat下用什么mysql驱动来驱动myql数据库呀?
- java.net.uri
- 如何通过一个字符串的值得到对应的类型
- 请问如何实现多项式的除法和最大公约式,用数组,非链表
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024);
我这儿显示是63 应该就是63m