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