Fixed multiple key handlers being registered on restarted game
This commit is contained in:
parent
b72fc8f1ca
commit
12cb4fd10f
@ -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<File> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user