请编写一个GUI程序,模拟显示相册:有4张图片,点击下一张按钮,循环显示4张图片。
注意:(1)图片保存在工程中的res文件夹,并定义字符串数组来保存图片的位置
String[] imageUrls = {
“application/res/1.png”,
“application/res/2.png”
}
Image[] images = new Image[3];
(2)加载图片
for(int i=0; i<images.length; i++)
{
images[i] = new Image(imageUrls[i]);
}
(所用工具为IntelliJ IDEA,可能与eclipse略有不同)
代码如下:
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.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx