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.*;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.KeyListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -17,6 +18,8 @@ public class ApplicationFrame implements Runnable
|
|||||||
|
|
||||||
private JList<File> filelist;
|
private JList<File> filelist;
|
||||||
|
|
||||||
|
private KeyListener keyHandler = new Control.KeyHandler();
|
||||||
|
|
||||||
private class ListMouseHandler extends MouseAdapter{
|
private class ListMouseHandler extends MouseAdapter{
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@ -47,6 +50,7 @@ public class ApplicationFrame implements Runnable
|
|||||||
|
|
||||||
public void backToMapSelection() {
|
public void backToMapSelection() {
|
||||||
jframe.remove(gamepanel);
|
jframe.remove(gamepanel);
|
||||||
|
jframe.removeKeyListener(keyHandler);
|
||||||
initMapselector();
|
initMapselector();
|
||||||
jframe.remove(mapselectorpanel);
|
jframe.remove(mapselectorpanel);
|
||||||
jframe.add(mapselectorpanel);
|
jframe.add(mapselectorpanel);
|
||||||
@ -81,7 +85,7 @@ public class ApplicationFrame implements Runnable
|
|||||||
|
|
||||||
private void setGameParams(File dungeonFile) throws IOException {
|
private void setGameParams(File dungeonFile) throws IOException {
|
||||||
gamepanel = new Display();
|
gamepanel = new Display();
|
||||||
jframe.addKeyListener(new Control.KeyHandler());
|
jframe.addKeyListener(keyHandler);
|
||||||
Game.instance.setDisplay(gamepanel);
|
Game.instance.setDisplay(gamepanel);
|
||||||
Game.instance.setDungeon(new Dungeon());
|
Game.instance.setDungeon(new Dungeon());
|
||||||
Game.instance.startGame(dungeonFile);
|
Game.instance.startGame(dungeonFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user