package game;

import javax.swing.JPanel;

public abstract class MovablePanel extends JPanel implements IMovable {

    protected int directionX;
    
    protected int directionY;
    
    protected int x;
    
    protected int y;
    
    protected int speed;

    /**
     * {@inheritDoc}
     */
    public void moveLeft() {
        directionX = -1;
        directionY = 0;
        performMove();
    }
    
    /**
     * {@inheritDoc}
     */
    public void moveRight() {
        directionX = 1;
        directionY = 0;
        performMove();
    }
    
    /**
     * {@inheritDoc}
     */
    public void moveUp() {
        directionX = 0;
        directionY = -1;
        performMove();
    }
    
    /**
     * {@inheritDoc}
     */
    public void moveDown() {
        directionX = 0;
        directionY = 1;
        performMove();
    }

    /**
     * Perform the actual move
     */
    protected void performMove() {
        x += directionX * speed;
        y += directionY * speed;
    }

    /**
     * Get X coordinate
     *
     * @return int x
     */
    public int getX() {
        return x;
    }

    /**
     * Get Y coordinate
     *
     * @return int y
     */
    public int getY() {
        return y;
    }

    /**
     * Get X direction
     *
     * @return int directionX
     */
    public int getDirectionX() {
        return x;
    }

    /**
     * Get Y direction
     *
     * @return int directionY
     */
    public int getDirectionY() {
        return y;
    }

    /**
     * Get the moving speed
     *
     * @return int number of pixels per move
     */
    public int getSpeed() {
        return speed;
    }

    /**
     * Set the moving speed
     * @param int speed number of pixels per move
     */
    public void setSpeed(int speed) {
        this.speed = speed;
    }

}
@@ -36,16 +36,268 @@
 Panel;%0A%0A
+/**%0A * I am a MovablePanel:%0A *  - I move%0A *  - I have a position (x,y)%0A *  - I have a direction (x,y)%0A *  - I have a speed (pixels in direction per move)%0A *%0A * If you need my move behavior%0A * you could ovveride my protected %60performMove()%60 method.%0A */%0A
 public a

Add more javadoc to game.MovablePanel