I'm trying to get a rectangle in my JFrame to move when I press a given key on the keyboard, but I'm seemingly having a hard time doing that. Here's my code:

```
package TestPackage;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JComponent;

public class Mainframe extends JComponent implements KeyListener
{
    private static final long serialVersionUID = 1L;

    int x = 350;
    int y = 250;

    public static void main (String[] args)
    {
        JFrame frame = new JFrame ("Mainframe");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        frame.setSize (800, 600);
        frame.setFocusable (true);
        frame.getContentPane().setBackground (Color.WHITE);
        frame.getContentPane().add (new Mainframe());
        frame.addKeyListener (new Mainframe());
        frame.setVisible (true);
    }

    public void paint (Graphics graphics)
    {
        graphics.setColor (Color.BLACK);
        graphics.fillRect (x, y, 100, 100);
    }

    public void keyPressed (KeyEvent event)
    {
        if (event.getKeyCode() == KeyEvent.VK_A)
        {
            x++;
            repaint();
        }
        else if (event.getKeyCode() == KeyEvent.VK_D)
        {
            y++;
            repaint();
        }
    }

    public void keyReleased (KeyEvent event) {}
    public void keyTyped (KeyEvent event) {}
}

```

I'm sure it's a problem with my KeyListener, as everything else works perfectly. Does anybody know what I'm doing wrong? Thanks.