moving an image

I am trying to move an image.

But it only moves one Pixel at the beginning, when I click on the image.

What could I do?

Is there a function that is called every Screen-Sync or something like that?

import java.applet.*;

import java.awt.*;

publicclass meinBildextends Applet{

Image EricsBild;

int x,y;

publicvoid init(){

EricsBild = getImage(getCodeBase(),"lippen.jpg");

x=5;y=5;

}

publicvoid paint(Graphics g){

if (x<200) x++;

if (x>200) x--;

if (y<200) y++;

g.drawImage(EricsBild,x,y,this);

}

}

[1284 byte] By [EricFalbea] at [2007-11-26 16:02:46]
# 1

You shouldn't change state (such as the (x,y) coordinates of the image) in the paint() method. The paint() method should just display the current state of your object or application, and something else should update the state.

If you want the image to seem to move by itself (and not just when, say, you click a button) then you can use a Thread or a java.util.Timer and java.util.TimerTask.

paulcwa at 2007-7-8 22:24:36 > top of Java-index,Java Essentials,New To Java...