1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| package essai_affichage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Collections;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class main extends Application {
@Override
public void start(Stage primaryStage) throws InterruptedException, FileNotFoundException {
ImageView imageView = new ImageView();
Button imageButton = new Button("Click Me");
ObservableList<Image> imagesList = FXCollections.observableArrayList();
FileInputStream inputstream = new FileInputStream("/home/village/Téléchargements/red.jpg");
imagesList.add(new Image(inputstream));
inputstream = new FileInputStream("/home/village/Téléchargements/blue.jpg");
imagesList.add(new Image(inputstream));
inputstream = new FileInputStream("/home/village/Téléchargements/green.jpg");
imagesList.add(new Image(inputstream));
ObjectProperty<Image> imageObjectProperty = new SimpleObjectProperty<>();
imageObjectProperty.bind(Bindings.valueAt(imagesList,0));
imageView.setFitHeight(100);
imageView.setFitWidth(100);
imageView.imageProperty().bind(imageObjectProperty);
Group root = new Group();
Scene scene = new Scene(root);
HBox box = new HBox();
box.getChildren().add(imageView);
box.getChildren().add(imageButton);
root.getChildren().add(box);
primaryStage.setScene(scene);
primaryStage.show();
imageButton.setOnAction(event -> {
Collections.rotate(imagesList,1);
});
}
public static void main(String[] args) {
launch(args);
}
} |
Partager