whats the problem in following code , why the ractangle not going to x++
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
class class2 extends JFrame implements Runnable,KeyListener
{ public int width =500;
public int height=300;
public int x=30;
public int y=50;
public Thread t;
private boolean r;
class2()
{ //setIconImage(Toolkit.getDefaultToolkit().getImage( "C:\\Users\\user\\Desktop\\Snake Costume\\handpainted_cartoon_snake_05_vector_18140 0.jpg"));
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width/3-this.getSize().width/2, dim.height/3-this.getSize().height/2);
setSize(width,height);
setResizable(false);
setVisible(true);
t =new Thread();
t.start();
}
/*paint classess*/
public void paint(Graphics g)
{
super.paintComponents(g);
paint1(g);
}
public void paint1(Graphics g)
{ g.setColor(Color.BLUE);
g.fillRect(x, y, 30, 20);
}
public void paint2(Graphics g)
{
}
@Override
public void run()
{
while(true)
{x++;
try{
Thread.sleep(100);
repaint();
}
catch(InterruptedException e)
{
e.setStackTrace(null);
}
}
}
/* control classess */
@Override
public void keyPressed(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
public class class1 {
public static void main(String args[])
{
new class2();
}
}