rectangle is not moving in java?

I am new in java

I am trying to make simple game but my first problem is that my rectangle is not moving

I have some problem in this code that when I am run the program my rectangle is not moving

with arrow keys..

This is my code..

public class gameseeting extends JPanel implements ActionListener, KeyListener

{

Timer tt= new Timer(5, this);

int x=2, y=210, velx=0,vely=0;

gameseeting ()

{

tt.start();

setFocusable(true);

addKeyListener(this);

setFocusTraversalKeysEnabled(false);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

g.drawRect(x, y, 40, 50);

}

public void actionPerformed(ActionEvent ae)

{

x += velx;

y += vely;

repaint();

}

public void keyPressed(KeyEvent e)

{

int code = e.getKeyCode();

if (code == KeyEvent.VK_DOWN){

vely = 1;

velx = 0;

}

if...

Read More »

By: StackOverFlow - Monday, 16 April

Related Posts