Moving a Rectangle using Keys I am working on making it so I can move a Rectangle using my arrow keys but what I have currently isn't working. 

I initially had it so the Rectangle moved on it's own when I started the program. It moves based on the values of xVelocity and yVelocity. When I change those to 0 the object is stationary (as expected). But when I make it so they are initially 0 and when you press an arrow key the velocity changes, the object doesn't move. Any help?

Here is my Main class, Shapes. I have the keyListener in here print out the Velocity value when I press DOWN so I know it is changing the velocity properly.

package square;

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

public class Shapes extends JFrame {

public static int WIN_WIDTH = 400;
public static int WIN_HEIGHT = 400;

private Paddle paddle = new Paddle();

public Shapes() {
    Panel panel = new Panel();

    setSize(WIN_WIDTH, WIN_HEIGHT);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    add(panel);
    panel.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyPressed(KeyEvent e) {
            int keyCode = e.getKeyCode();
            if(keyCode == KeyEvent.VK_DOWN) {
                paddle.yVelocity = -4;
                System.out.println(paddle.yVelocity);
            }
            if(keyCode == KeyEvent.VK_UP) {
                paddle.yVelocity = 4;
            }
            if(keyCode == KeyEvent.VK_RIGHT) {
                paddle.xVelocity = 4;
            }
            if(keyCode == KeyEvent.VK_LEFT) {
                paddle.xVelocity = -4;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {

        }
    });
    setVisible(true);
}

public static void main(String[] args) {
    new Shapes();
}
}


Here is my Paddle class where the shape's values are stored, drawn, and updated. I have the velocities set to 0 initially

package square;

import java.awt.*;

public class Paddle {

int RECT_WIDTH = 200;
int RECT_HEIGHT = 100;
int x = Shapes.WIN_WIDTH/2-100;
int y = Shapes.WIN_HEIGHT/2-50;
int xVelocity = 0;
int yVelocity = 0;

public void paint(Graphics g) {
    g.setColor(Color.red);
    g.fillRect(x, y, RECT_WIDTH, RECT_HEIGHT);
}

public void update() {
    x += xVelocity;
    y += yVelocity;
    if(x &lt; 0 || x &gt; Shapes.WIN_WIDTH) {
        xVelocity = -xVelocity;
    }
    if(y &lt; 0 || y &gt; Shapes.WIN_HEIGHT) {
        yVelocity = -yVelocity;
    }
}
}


And finally my Panel class

package square;

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

public class Panel extends JPanel implements ActionListener {

Paddle paddle = new Paddle();
Timer timer;

public Panel() {
    this.setFocusable(true);
    timer = new Timer(5,this);

    timer.start();
}

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    paddle.paint(g);
}

public void update() {
    paddle.update();
}

@Override
public void actionPerformed(ActionEvent e) {
    repaint();
    update();
}
}
The reason the position of the paddle doesn't update is because the paddle that you adjust the velocity of in class Shapes is a different instance of paddle than the one you're drawing.
Make these changes to class Shapes: 

delete field: private Paddle paddle = new Paddle();

add line 
Paddle paddle = panel.paddle;

in the constructor after you declare Panel panel = new Panel();

Additionally, you will likely want to switch your yVelocity values, as pressing "down" sends the box up, and vice versa.