Ich habe ein Problem mit einem Spiel das unsere Abschlussprojekt für dieses Schuljahr sein soll. Ich habe zwei klassen. in der ersten ist das fenster mit einemJLayeredPane und 5 JLabels. dort habe ich die steuerung über keylistener und das zeichnen von kleinen kugeln (im spiel sind das dann die schüsse) im zweiten programm habe ich dann die bewegung des gegners programmiert dabei soll das jlabel im ersten programm verändert werden. doch wenn ich das programm starte stürtzt es nach ein paar sekunden ab und ich bekomm diesen riesige fehlermeldung.
Ich hab mal hier die quelltexte der beiden klassen.
1. Klasse
2. Klasse
Bitte um hilfe bis dienstag muss ich fertig werden und bin hier schon am verzweifeln
Code:
Exception in thread "Thread-232" java.lang.OutOfMemoryError: Java heap space
at com.sun.media.sound.SMFParser.readTrack(Unknown Source)
at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
at com.sun.media.sound.JavaSoundAudioClip.createSequencer(Unknown Source)
at com.sun.media.sound.JavaSoundAudioClip.<init>(Unknown Source)
at sun.applet.AppletAudioClip.createAppletAudioClip(Unknown Source)
at sun.applet.AppletAudioClip.<init>(Unknown Source)
at java.applet.Applet.newAudioClip(Unknown Source)
at Programme.Metroid.<init>(Metroid.java:50)
at Programme.MetroidGegner.<init>(MetroidGegner.java:12)
at Programme.Metroid.gegner(Metroid.java:224)
at Programme.Metroid.run(Metroid.java:216)
at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-5" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at javax.sound.midi.Track.add(Unknown Source)
at com.sun.media.sound.SMFParser.readTrack(Unknown Source)
at com.sun.media.sound.StandardMidiFileReader.getSequence(Unknown Source)
at javax.sound.midi.MidiSystem.getSequence(Unknown Source)
at com.sun.media.sound.JavaSoundAudioClip.createSequencer(Unknown Source)
at com.sun.media.sound.JavaSoundAudioClip.<init>(Unknown Source)
at sun.applet.AppletAudioClip.createAppletAudioClip(Unknown Source)
at sun.applet.AppletAudioClip.<init>(Unknown Source)
at java.applet.Applet.newAudioClip(Unknown Source)
at Programme.Metroid.<init>(Metroid.java:50)
at Programme.MetroidGegner.<init>(MetroidGegner.java:12)
at Programme.Metroid.gegner(Metroid.java:224)
at Programme.Metroid.run(Metroid.java:216)
at java.lang.Thread.run(Unknown Source)
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d48a38b, pid=1512, tid=704
#
# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing windows-x86)
# Problematic frame:
# C [jsound.dll+0xa38b]
#
# An error report file with more information is saved as:
# C:\test_eclipse_eclipseuml\Eclipse 3.2\hs_err_pid1512.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Ich hab mal hier die quelltexte der beiden klassen.
1. Klasse
Java:
package Programme;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Panel;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
import java.applet.AudioClip;
import java.applet.Applet;
import java.net.URL;
public class Metroid extends JFrame implements ActionListener, KeyListener, Runnable
{
JLabel Metroid, Background, Samus, Lebenspunkte, Punkte;
JLayeredPane jlp = new JLayeredPane();
int r=0,l=0,o=0,m=0,e=99,p=0,x=249,y=122;
boolean m1=true;
MetroidGegner monster;
public Metroid()
{
super("Metroid");
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
}
);
try
{
URL u = new URL("file:/C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/prologue.mid");
AudioClip clip = Applet.newAudioClip(u);
clip.loop();
}
catch (Exception e)
{}
Background = new JLabel();
Background.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroid Map.png"));
Background.setBounds(0,0,512,193);
Background.setVisible(true);
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Samus_Aran.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
Metroid = new JLabel();
Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroid.png"));
Metroid.setBounds(247,50,22,21);
jlp.add(Metroid, 0);
Lebenspunkte = new JLabel();
Lebenspunkte.setText(Integer.toString (e));
Lebenspunkte.setForeground(Color.white);
Lebenspunkte.setBounds(460,150,50,50);
Punkte = new JLabel();
Punkte.setText( Integer.toString (p));
Punkte.setForeground(Color.white);
Punkte.setBounds(40,150,50,50);
jlp.add(Background, 1);
jlp.add(Samus, 0);
jlp.add(Metroid, 0);
jlp.add(Lebenspunkte, 0);
jlp.add(Punkte, 0);
this.add(jlp);
addKeyListener(this);
}
public static void main(String[] args)
{
Metroid Versuch = new Metroid();
Versuch.setVisible(true);
Versuch.setSize(520, 225);
}
public void actionPerformed(ActionEvent e)
{
}
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_UP)
{
r=0;
l=0;
o=1;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Samus_Oben.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
if (e.getKeyCode() == KeyEvent.VK_LEFT)
{
r=0;
l=1;
o=0;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Samus_Links.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
{
r=1;
l=0;
o=0;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Samus_Rechts.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
if (e.getKeyCode() == KeyEvent.VK_SPACE)
{
if(r==1)
{
r=2;
x=270;
y=135;
}
if(l==1)
{
l=2;
x=245;
y=135;
}
if(o==1)
{
o=2;
x=260;
y=117;
}
startanimation();
}
}
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_UP)
{
r=0;
l=0;
o=0;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-200/Programme/Samus_Aran.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT)
{
r=0;
l=0;
o=0;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Samus_Aran.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
if (e.getKeyCode() == KeyEvent.VK_LEFT)
{
r=0;
l=0;
o=0;
Samus = new JLabel();
Samus.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009Programme/Samus_Aran.png"));
Samus.setBounds(249,122,21,38);
Samus.setOpaque(true);
Samus.setVisible(true);
jlp.add(Samus, 0);
}
}
public void keyTyped(KeyEvent e)
{
}
public void startanimation()
{
Thread Grafik = new Thread(this);
Grafik.start();
}
public void run()
{
gegner();
}
public void gegner()
{
Graphics grafik = Background.getGraphics();
while(m1==true)
{
monster = new MetroidGegner();
monster.MetroidGegner();
if(r==2)
{
x++;
grafik.setColor(new Color(0, 128, 128 ));
grafik.fillOval(x-1, y, 5, 5);
grafik.setColor(Color.yellow);
grafik.fillOval(x, y, 5, 5);
try {
Thread.sleep(10);
} catch (InterruptedException f) {
};
}
if(l==2)
{
x--;
grafik.setColor(new Color(0, 128, 128 ));
grafik.fillOval(x+1, y, 5, 5);
grafik.setColor(Color.yellow);
grafik.fillOval(x, y, 5, 5);
try {
Thread.sleep(10);
} catch (InterruptedException f) {
};
}
if(o==2)
{
y--;
grafik.setColor(new Color(0, 128, 128 ));
grafik.fillOval(x, y+1, 5, 5);
grafik.setColor(Color.yellow);
grafik.fillOval(x, y, 5, 5);
try {
Thread.sleep(10);
} catch (InterruptedException f) {
};
}
}
}
}
2. Klasse
Java:
package Programme;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
public class MetroidGegner extends JFrame implements Runnable
{
Metroid jlp = new Metroid();
int m=0;
boolean m1=true;
Metroid Metroid=new Metroid();
public void MetroidGegner()
{
startanimation2();
}
public void startanimation2()
{
Thread Grafik = new Thread();
Grafik.start();
}
public void run()
{
gegner();
}
public void gegner()
{
while(m1==true)
{
if(m==0)
{
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroid.png"));
Metroid.Metroid.setBounds(247,50,22,21);
jlp.add(Metroid, 0);
try
{
Thread.sleep(1000);
}
catch (InterruptedException f)
{
};
m=1;
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009Programme/Metroiddelete.png"));
Metroid.Metroid.setBounds(247,50,22,21);
jlp.add(Metroid, 0);
}
if(m==1)
{
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroid.png"));
Metroid.Metroid.setBounds(135,130,22,21);
jlp.add(Metroid, 0);
try
{
Thread.sleep(1000);
}
catch (InterruptedException f)
{
};
m=2;
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroiddelete.png"));
Metroid.Metroid.setBounds(135,130,22,21);
jlp.add(Metroid, 0);
}
if(m==2)
{
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-200/Programme/Metroid.png"));
Metroid.Metroid.setBounds(353,130,22,21);
jlp.add(Metroid, 0);
this.add(jlp);
try
{
Thread.sleep(1000);
}
catch (InterruptedException f)
{
};
m=0;
Metroid.Metroid.setIcon(new ImageIcon("C:/test_eclipse_eclipseuml/Eclipse 3.2/TGIEK 2008-2009/Programme/Metroiddelete.png"));
Metroid.Metroid.setBounds(353,130,22,21);
jlp.add(Metroid, 0);
}
}
}
}
Bitte um hilfe bis dienstag muss ich fertig werden und bin hier schon am verzweifeln
Zuletzt bearbeitet: