KeyListener not accepting function as override

53 views Asked by At

I have a JFrame called frame.
I initialize it like this:

    frame = new JFrame("Game"){{
        setSize(500, 600);
        setFocusable(true);
        setUndecorated(true);
        add(g);
        setVisible(true);
        setDefaultCloseOperation(3);
        addKeyListener(new KeyListener(){
            public void keyPressed(KeyEvent e){
                player.keyPress(e.getCharacter().toCharArray()[0]);
            }
            public void keyReleased(KeyEvent e){}
            public void keyTyped(KeyEvent e){}
        });
    }};

I get an error from the keylistener saying that I need to override its functions. I tried adding an @Override annotation, but it just tells me there's nothing to override. What have I done wrong?

1

There are 1 answers

0
James McDowell On BEST ANSWER

I found the problem. I was using netbeans auto-import and I imported the wrong keyEvent (from javafx)