package sample;import javafx.application.Application;import javafx.event.ActionEvent;import javafx.event.EventHandler;import javafx.scene.Scene;import javafx.scene.control.Button;import javafx.scene.image.Image;import javafx.scene.layout.BorderPane;import javafx.stage.Stage;import sun.security.provider.SHA;/*** 相册*/public class PhotoAlbum extends Application {//图片资源文件String imageUrl[]={"resource/8a6aff91645a9ad78dc5433fc3a8f85a823c498b.jpg","resource/2491e7013677c88a5b3170a2d5345106536c22b5.jpg","resource/a1cf5dd198d541b0817a3180a4fe4e0c.jpg"};//当前在第几张int currentIndex=0;Image[] images=new Image[imageUrl.length];javafx.scene.image.ImageView imageView= new javafx.scene.image.ImageView();@Overridepublic void start(Stage primaryStage) throws Exception {for (int i = 0; i < imageUrl.length; i++) {images[i]=new Image(imageUrl[i]);}BorderPane root = new BorderPane();Button button=new Button("下一张");button.setOnAction(new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent event) {showNext();}});imageView.setPreserveRatio(true);root.setTop(button);root.setCenter(imageView);primaryStage.setTitle("相册");primaryStage.setScene(new Scene(root, 880, 400));primaryStage.show();showNext();}public void showNext(){if(currentIndex>=imageUrl.length){currentIndex=0;}imageView.setFitHeight(images[currentIndex].getHeight());imageView.setFitWidth(images[currentIndex].getWidth());imageView.setImage(images[currentIndex]);currentIndex++;}public static void main(String[] args) {launch(args);}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。