这是我正在做的代码:
import java.net.*;
import java.applet.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import javax.sound.sampled.AudioFileFormat;
class GraphicsProgram extends Canvas
{
public GraphicsProgram()
{ setSize(200, 200);
setBackground(Color.PINK);
}
public static AudioFileFormat ee;
public static AudioClip ss;
public class NEW extends JApplet {
public void init() {
ss = Applet.newAudioClip(Get_Location("/pj1/anarkali.wav"));
ss.play();}
public URL Get_Location(String filename)
{
URL url = null;
try{ url=this.getClass().getResource(filename);
}
catch(Exception e){}
return url;
}
}
public static void main(String[] argS)
{
GraphicsProgram GP = new GraphicsProgram();
//create a new frame to which we will add a canvas
Frame aFrame = new Frame(); aFrame.setSize(800, 800);
//add the canvas
aFrame.add(GP);
aFrame.setVisible(true); }
public void paint(Graphics g)
{
Image img01 = Toolkit.getDefaultToolkit().getImage("e:\\m.gif");
g.drawImage(img01, 110, 140, this);
Image img0 = Toolkit.getDefaultToolkit().getImage("e:\\m10.jpg");
g.drawImage(img0, 100, 140, this);
Image img2 = Toolkit.getDefaultToolkit().getImage("e:\\m2.gif");
g.drawImage(img2, 200, 140, this);
NEW ss=new NEW();
ss.init();
}
}
我得到:线程“AWT-EventQueue-0”中的异常 java.lang.OutOfMemoryError:Java 堆空间
但是,我仍然可以运行它,它正在播放声音并显示图像。这可能吗?为什么我会出现堆空间错误?