试图在Javafx中将轮播包含计时器。
public class Controller {
@FXML
private ImageView imageslidder;
@FXML
private ImageView left;
@FXML
private ImageView right;
@FXML
private Circle picone;
@FXML
private Circle pictwo;
@FXML
private Circle picthree;
int imag_index = 0;
String images[] = new String []{"sample/one.jpg", "sample/two.jpg", "sample/three.jpg"};
void nextImage() {
switch (imag_index) {
case 0:
setStroke(picone);
resetStroke(pictwo);
resetStroke(picthree);
break;
case 1:
setStroke(pictwo);
resetStroke(picone);
resetStroke(picthree);
break;
case 2:
setStroke(picthree);
resetStroke(pictwo);
resetStroke(picone);
break;
default:
break;
}
imag_index++;
if (imag_index == images.length) ;
{
imag_index = 0;
}
try {
String imagpath = getClass().getResource(images[imag_index]).toURI().toString();
Image img = new Image(imagpath);
imageslidder.setImage(img);
} catch (Exception e) {
}
}
void prevImage() {
nextImage();
}
void setStroke(Circle indicator) {
indicator.setFill(Paint.valueOf("#03a9f4"));
indicator.setStroke(Paint.valueOf("#cddc39"));
indicator.setStrokeType(StrokeType.OUTSIDE);
indicator.setStrokeWidth(5);
}
void resetStroke(Circle indicator) {
indicator.setFill(Paint.valueOf("ffffff"));
indicator.setStroke(Paint.valueOf("#1e90ff"));
indicator.setStrokeType(StrokeType.INSIDE);
indicator.setStrokeWidth(1);
}
public void initializer(URL url, ResourceBundle rb)
{
}
}