hello, hello! im probably being really dumb again, but i can't get java to run keyPressed() when i press a key. do i need to initialize the keylistener somewhere? any input is appreciated!(even if it's not help)

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JPanel;
import javax.swing.Timer;

public class GamePanel extends JPanel implements ActionListener, KeyListener{

    Blocks blocks = new Blocks();
    Player player = new Player();

    public GamePanel(){

        Timer tim = new Timer(50, this);
        tim.start();
        setFocusable(true);
        setFocusTraversalKeysEnabled(false);

    }

    private void update(){

        blocks.update();
        player.update();

    }

    public void paintComponent(Graphics g){

        blocks.paint(g);
        player.paint(g);

    }

    public void actionPerformed(ActionEvent e){

        update();
        repaint();



    }

    // key listeners

    public void keyPressed(KeyEvent e) {

        System.out.println("a down");

    }

    public void keyReleased(KeyEvent e) {



    }

    public void keyTyped(KeyEvent e) {



    }

}

thank you.

Has a keylistener been added?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.