public class Basics extends Applet{
int x = 0;
int y = 0;
public void init(){
setSize(500,500);
}
public void start(){
Thread a = new Thread();
a.start();
}
public void run(){
while(true){
x = 100;
y = 100;
repaint();
try{
Thread.sleep(18);
}
catch(InterruptedException e){}
}
public void paint(Graphics g){
g.setColor(Color.red);
g.fillRect(this.x,this.y,25,25);
}
}
Shouldnt incrementing x and y and then repainting allow the square to move
You should increment your x and y value, now you are only assigning values to it. Change it like this:
public void run(){
while(true){
x += 100;
y += 100;
repaint();
try{
Thread.sleep(18);
}
catch(InterruptedException e){}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With