Ошибка KeyListener - класс не переопределяет - PullRequest
0 голосов
/ 19 ноября 2018

У меня проблемы с использованием KeyListener. Я получаю сообщение об ошибке, в котором говорится, что Контроллер не является абстрактным и не переопределяет абстрактный метод keyReleased (java.awt.event.KeyEvent) в java.awt.event.KeyListener, но я уже реализовал keyReleased. Есть ли другие предложения по исправлению? Ниже мой код:

public class Controller extends JPanel implements KeyListener, Runnable{
//EventHandler<KeyEvent>{

    @FXML private Label scoreLabel;
    @FXML private Label messageLabel;
    @FXML private GameView gameView;

    private Thread thread;
    private boolean running = false;
    private Scene scene;
    Timer timer;

    private Model model;

    public Controller() {

    }

    public void keyPressed(KeyEvent e) {
        KeyCode code = e.getCode();
        if (code == KeyCode.LEFT || code == KeyCode.A) {
            this.model.setDirection("left");
        } else if (code == KeyCode.RIGHT || code == KeyCode.D) {
            this.model.setDirection("right");
        }
    }

    public void keyTyped(KeyEvent e){}

    public void keyReleased(KeyEvent e){}

    public void initialize() {
        this.model = new Model(this.gameView.getRowCount(),this.gameView.getColumnCount());
        timer = new Timer();
        this.update();
    }


    private void update() {
        if (this.model.getDirection().equals("right")){this.model.moveMoodler("right");}
        else if (this.model.getDirection().equals("left"){this.model.moveMoodler("left");}
        this.gameView.update(this.model);
    }

    public double getBoardWidth() {
        return GameView.CELL_WIDTH * this.gameView.getColumnCount();
    }

    public double getBoardHeight() {
        return GameView.CELL_WIDTH * this.gameView.getRowCount();
    }

    public void start(Scene scene) {
        thread = new Thread(this);
        this.scene = scene;
        thread.start();
        running = true;
    }

    public void stop() {
        try {
            thread.join();
            running = false;
        }catch(Exception e) {
            e.printStackTrace();
       }
    }

    public void run() {
        TimerTask task = new TimerTask()
        {
            public void run()
            {
                //System.out.println("In timer task");
                model.move();
                update();
            }
        };
        while (true) {
            timer.schedule(task, 100);
        }
    }

    public void tick() {

    }

    public void render() {

    }


    /**
     * Pops up start page
     * Transitions into playGame mode after
     * start button is pressed
     */
    public void startGame(){

    }

    /**
     * Moves from playing game page to end page
     * Updates high score if need be
     * Offers replay button
     */
    public void endGame() {

    }

    /**
     * Takes user input to play the actual game
     */
    public void playGame(){

    }
}

Спасибо! * * 1004

...