Help with KeyAdapter

Hi, im trying to recreat pong for my summative progect at school and i need a little help
Im using a KeyAdapter to get the KeyEvent from the user and to move the paddle corespondingly, but it not registering and im really confused
help would be much appreciated,

/**
 * 
 */
package ShahabGame;

import javax.swing.*;
import java.awt.event.*;

public class ShahabPongGame extends JFrame
{
	Ball ball = new Ball(20,20);
	
	public static void main(String[] args)
	{
		new ShahabPongGame();
	}
	ShahabPongGame()
	{
		add(ball);
		setSize(400, 400);
		setVisible(true);
		addKeyListener(new KeyAdapter(){
			public void keyPressed (KeyEvent e)
			{
				System.out.println(e.getKeyCode());
				if(e.getKeyCode() == 38)
				{
					//up
					ball.updatePaddel(38);
					System.out.println("Up");
				}
				if(e.getKeyCode() == 39)
				{
					//right
					ball.updatePaddel(39);
				}
				if(e.getKeyCode() == 40)
				{
					//down
					ball.updatePaddel(40);
				}
				if(e.getKeyCode() == 37)
				{
					//left
					ball.updatePaddel(37);
				}
			}
		}
		);
	}

	
	

}

Thanks

you might have to add your key listener to the contentpane

jframe.getContentPane().addKeyListener

unfortunately that didn’t work but thanks for the suggestion
i tried to use and inner class or a key adapter but those don’t seem to work either

public class ShahabPongGame extends JFrame
{
	Ball ball = new Ball(20,20);
	
	
	
	public static void main(String[] args)
	{
		new ShahabPongGame();
	}
	public ShahabPongGame()
	{
		MyListener listener = new MyListener();
		add(ball);
		setSize(400, 400);
		setVisible(true);
		addKeyListener(new MyListener());
		setFocusable(true);
		/*addKeyListener(new KeyAdapter(){
			public void keyPressed(KeyEvent e)
			{
				System.out.println(e.getKeyCode());
				int i = e.getKeyCode();
				switch(i)
				{
					case 37:
						System.out.println("Left");
						//ball.updatePaddel(37);
						break;
					case 38:
						ball.updatePaddel(38);
						break;
					case 39:
						ball.updatePaddel(39);
						break;
					case 40:
						ball.updatePaddel(40);
						break;
				}
		}
		});*/
	}
	private class MyListener extends KeyAdapter
	{
		public void keyPressed(KeyEvent e)
		{
			System.out.println("Okay");
		}
	}

try a requestFocus() after adding the listener

is that you whole code ? or is there something in your frame ?

=> what I mean is maybe something you added in front catch key events

have you tried implementing keylistener?

Dzzd ya it’s my whoole code the add(ball) referes to another class with a paint method

h3ckboy i’ve tried implementing a KeyListener but im will try again just to make sure that for the suggestion

cylab i tried adding that in but it didin’t work

It worked fine for me, all I did was remove your commented out code(and calls to ball).

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;

public class ShahabPongGame extends JFrame
{
	//Ball ball = new Ball(20,20);
	
	
	
	public static void main(String[] args)
	{
		new ShahabPongGame();
	}
	public ShahabPongGame()
	{
		MyListener listener = new MyListener();
		//add(ball);
		setSize(400, 400);
		setVisible(true);
		addKeyListener(new MyListener());
		setFocusable(true);
		
	}
	private class MyListener extends KeyAdapter
	{
		public void keyPressed(KeyEvent e)
		{
			System.out.println("Okay");
		}
	}
}

ya but the problem is when i start create my ball then put it in the frame
Then it stopd working, it stop printing okay and just does nothing other than show the art

Can you post the Ball code?