I'm honestly not sure if the title fits the question completely, but here it is anyway. I'm making a simple game in java where alien spaceships fall down from the top of the screen and if you don't kill them and they get to the bottom of the screen, the space station takes damage. But whenever the space station gets destroyed, the message-box that should tell the player that they died, won't stop appearing, it just keeps popping up over and over again. And in the console I get an error message that won't stop getting bigger! This is the code I have for the space station's health:
public class SpaceStation extends Entity {
public static int stationHealth = 100;
public SpaceStation(int x, int y) {
super(x, y);
}
public void update() {
}
public void draw(Graphics2D g2d) {
g2d.drawImage(ImageLocator.getSpaceStation(), 0, 595, null);
// HEALTH BAR
g2d.fillRect(5, 25, stationHealth, 10);
if(stationHealth <= 0) {
try{
JOptionPane.showMessageDialog(null, "You died on level "
+ GameFrame.level + ". Better luck next time!");
GameFrame.mainTimer.stop();
System.exit(0);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
System.exit(0);
}
}
}
public Rectangle getBounds() {
return new Rectangle(x, y, 600, 200);
}
}
Apparently the line that the error is on is the JOptionPane.showMessageDialog(null, "You died on level " Here's the error message:
at java.lang.Thread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.InternalError: The current process has used all of its system allowance of handles for Window Manager objects.
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.InternalError: The current process has used all of its system allowance of handles for Window Manager objects.
Thank you for your time.
actionListener
of theTimer
.ifGameOver()
returnstrue
, stop the timer and callassessWinner()
which might pop the 'your character has 0 health' (much nicer than 'got you, sucker') dialog. – Meganmeganthropus