Hallo Leute, ich habs jetzt!! Ich hab gleich zwei Lösungsvorschläge. Mir ist es ja fast schon unangenehm wegen so einer banalen Sache das Forum zu bemühen, aber wenigstens versperrt mir jetzt das Brett vorm Hirn nicht mehr die Sicht!
😀
[CODE]public class Bewegung {
Timer move;
static int x = 0, y = 130;
static int vx = 1;
public Bewegung() {
move = new Timer();
move.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
x = x + vx;
if (x < 0 || x > 470) {
vx = -vx;
}
}
}, 0, 6);
}
}
[/CODE]
die zweiter Variante ist etwas Aufwendiger, funktioniert aber auch:
[CODE]public class Bewegung {
Timer move;
static int x = 0, y = 130;
static int delay = 0;
public Bewegung() {
move = new Timer();
move.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
delay++;
if (delay <= 470) {
x += 1;
}
if ((delay >= 480) && (delay < 950)){
x -= 1;
}
if((delay >= 960) && (delay < 1430)) {
x += 1;
}
if((delay >=1440)&& (delay <1910)) {
x -= 1;
}
if(delay > 1920){
{x=0; delay = 0;}
}
}
}, 0, 6);
}
}
[/CODE]
Danke nochmals für die Hinweise!!!