I'm writing a program that shows an image that will move when you move the slider. I am getting problem at the listener part. How do I actually check if the slider is moving and in which direction?
private class CarListener implements ChangeListener{
int x = car.getX();
public void stateChanged(ChangeEvent e){
if (){ //If slider goes right
x++;
pp.showImage(imga, x, 10);
}
else if (){ //If slider goes left
x--;
pp.showImage(imga, x, 10);
}
}
You can get the value from your slider by calling .getValue() on it. Then you can compare it to the last known value. In your case you could even just update x with the value of the slider.
Edit: .getValue() returns an int of course, so just cast it.