diff --git a/cicaprojekt/ApplicationFrame.java b/cicaprojekt/ApplicationFrame.java index 1ee98bb..f799577 100644 --- a/cicaprojekt/ApplicationFrame.java +++ b/cicaprojekt/ApplicationFrame.java @@ -3,6 +3,7 @@ package cicaprojekt; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; +import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; @@ -17,6 +18,8 @@ public class ApplicationFrame implements Runnable private JList filelist; + private KeyListener keyHandler = new Control.KeyHandler(); + private class ListMouseHandler extends MouseAdapter{ @Override public void mouseClicked(MouseEvent e) { @@ -47,6 +50,7 @@ public class ApplicationFrame implements Runnable public void backToMapSelection() { jframe.remove(gamepanel); + jframe.removeKeyListener(keyHandler); initMapselector(); jframe.remove(mapselectorpanel); jframe.add(mapselectorpanel); @@ -81,7 +85,7 @@ public class ApplicationFrame implements Runnable private void setGameParams(File dungeonFile) throws IOException { gamepanel = new Display(); - jframe.addKeyListener(new Control.KeyHandler()); + jframe.addKeyListener(keyHandler); Game.instance.setDisplay(gamepanel); Game.instance.setDungeon(new Dungeon()); Game.instance.startGame(dungeonFile);