老实说,我不确定标题是否完全符合问题,但无论如何。我正在用java制作一个简单的游戏,外星飞船从屏幕顶部掉下来,如果你不杀死它们并且它们到达屏幕底部,空间站就会受到伤害。但是每当空间站被摧毁时,应该告诉玩家他们死了的消息框不会停止出现,它只会一遍又一遍地弹出。在控制台中,我收到一条不会停止变大的错误消息!这是我对空间站健康的代码:
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);
}
}
显然错误所在的行是 JOptionPane.showMessageDialog(null, "You dead on level " 这是错误消息:
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.
感谢您的时间。