KeyListener won't work
<h1>KeyListener won't work </h1><br>
I try to test my graphic program by create a circle then add key listener on them and make them work.<br>
But I seen it does not work! But the graphic work well!<br>
So, can you correct the code for me!<br>
I'm work on Windows 7 with eclipse (Indigo)<br>
Thank you for supporting<br>
<hr>


    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    
    import javax.swing.*; //AWT extends
    
    public class dotMoveByArrow extends JPanel implements ActionListener, KeyListener {
    
    	Timer t = new Timer(5, (ActionListener) this);
    	double x = 0, y = 0, velX = 2, velY= 2;
    	
    	public void dotMoveByArrow() {
    		
    		t.start();
    		addKeyListener(this);
    		setFocusable(true);
    		setFocusTraversalKeysEnabled(false);
    		setVisible(true);
    	}
    	
    	public void paintComponent(Graphics g) {
    		
    		super.paintComponents(g);
    		Graphics2D g2 = (Graphics2D) g;
    		Ellipse2D circle = new Ellipse2D.Double(x, y, 40, 40);
    		g2.fill(circle);
    	}
    	
    	public void actionPerformed(ActionEvent event) {
    		
    		repaint();
    		x += velX;
    		y += velY;
    	}
    
    	public void up() {
    		
    		velY = -1.5;
    		velX = 0;
    	}
    
    	public void down() {
    		
    		velY = 1.5;
    		velX = 0;
    	}
    	
    	public void left() {
    		
    		velX = -1.5;
    		velY = 0;
    	}
    	
    	public void right() {
    		
    		velX = 1.5;
    		velY = 0;
    	}
    	
    	public void keyPressed(KeyEvent event) {
    		
    		int key = event.getKeyCode();
    		if (key == KeyEvent.VK_UP) {
    			
    			up();
    			System.out.println("up");
    		}
    		
    		if (key == KeyEvent.VK_DOWN) {
    			
    			down();
    			System.out.println("down");
    		}
    		
    		if (key == KeyEvent.VK_LEFT) {
    			
    			left();
    			System.out.println("left");
    		}
    		
    		if (key == KeyEvent.VK_RIGHT) {
    			
    			right();
    			System.out.println("right");
    		}
    	}
    
    	public void keyReleased(KeyEvent arg0) {}
    
    	public void keyTyped(KeyEvent arg0) {}
    	
    	public static void main(String[] args) {
            
    		dotMoveByArrow d = new dotMoveByArrow();
    		JFrame f = new JFrame();
    		
    		f.getContentPane().add(d);
    		f.setBackground(new Color(255, 255, 255));
    		f.setUndecorated(true);
    		f.setVisible(true);
    		f.setSize(640, 480);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setTitle("Dot Move by Arrow");
        }
    }
KeyListener won't work
===

<h1>KeyListener won't work </h1><br>
I try to test my graphic program by create a circle then add key listener on them and make them work.<br>
But I seen it does not work! But the graphic work well!<br>
So, can you correct the code for me!<br>
I'm work on Windows 7 with eclipse (Indigo)<br>
Thank you for supporting<br>
<hr>


    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    
    import javax.swing.*; //AWT extends
    
    public class dotMoveByArrow extends JPanel implements ActionListener, KeyListener {
    
    	Timer t = new Timer(5, (ActionListener) this);
    	double x = 0, y = 0, velX = 2, velY= 2;
    	
    	public void dotMoveByArrow() {
    		
    		t.start();
    		addKeyListener(this);
    		setFocusable(true);
    		setFocusTraversalKeysEnabled(false);
    		setVisible(true);
    	}
    	
    	public void paintComponent(Graphics g) {
    		
    		super.paintComponents(g);
    		Graphics2D g2 = (Graphics2D) g;
    		Ellipse2D circle = new Ellipse2D.Double(x, y, 40, 40);
    		g2.fill(circle);
    	}
    	
    	public void actionPerformed(ActionEvent event) {
    		
    		repaint();
    		x += velX;
    		y += velY;
    	}
    
    	public void up() {
    		
    		velY = -1.5;
    		velX = 0;
    	}
    
    	public void down() {
    		
    		velY = 1.5;
    		velX = 0;
    	}
    	
    	public void left() {
    		
    		velX = -1.5;
    		velY = 0;
    	}
    	
    	public void right() {
    		
    		velX = 1.5;
    		velY = 0;
    	}
    	
    	public void keyPressed(KeyEvent event) {
    		
    		int key = event.getKeyCode();
    		if (key == KeyEvent.VK_UP) {
    			
    			up();
    			System.out.println("up");
    		}
    		
    		if (key == KeyEvent.VK_DOWN) {
    			
    			down();
    			System.out.println("down");
    		}
    		
    		if (key == KeyEvent.VK_LEFT) {
    			
    			left();
    			System.out.println("left");
    		}
    		
    		if (key == KeyEvent.VK_RIGHT) {
    			
    			right();
    			System.out.println("right");
    		}
    	}
    
    	public void keyReleased(KeyEvent arg0) {}
    
    	public void keyTyped(KeyEvent arg0) {}
    	
    	public static void main(String[] args) {
            
    		dotMoveByArrow d = new dotMoveByArrow();
    		JFrame f = new JFrame();
    		
    		f.getContentPane().add(d);
    		f.setBackground(new Color(255, 255, 255));
    		f.setUndecorated(true);
    		f.setVisible(true);
    		f.setSize(640, 480);
    		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		f.setTitle("Dot Move by Arrow");
        }
    }