/
alex_ep0411
/
java_lab3
Обзор
Документация
Войти
/
alex_ep0411
/
java_lab3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/ImageIterator.java
89 строк
2 KB
александр
лабораторная работа 3
08 июн 2026, 12:17
08 июн 2026, 12:17
3ce77bb
Код
Авторство
О чём код?
import javafx.scene.image.Image; import java.io.File; import java.util.ArrayList; import java.util.List; public class ImageIterator { private List<File> images; private int currentPosition; public ImageIterator() { this.images = new ArrayList<>(); this.currentPosition = 0; } public void loadImages(String folderPath) { File folder = new File(folderPath); images.clear(); if (!folder.exists()) { folder.mkdir(); return; } File[] files = folder.listFiles(); if (files != null) { for (File file : files) { String name = file.getName().toLowerCase(); if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png") || name.endsWith(".gif")) { images.add(file); } } } currentPosition = images.isEmpty() ? 0 : 0; } public Image getCurrentImage() { if (images.isEmpty()) return null; return new Image(images.get(currentPosition).toURI().toString()); } public File getCurrentFile() { if (images.isEmpty()) return null; return images.get(currentPosition); } public void next() { if (images.isEmpty()) return; currentPosition++; if (currentPosition >= images.size()) { currentPosition = 0; } } public void previous() { if (images.isEmpty()) return; currentPosition--; if (currentPosition < 0) { currentPosition = images.size() - 1; } } public void first() { if (images.isEmpty()) return; currentPosition = 0; } public void last() { if (images.isEmpty()) return; currentPosition = images.size() - 1; } public int getCurrentIndex() { return currentPosition + 1; } public int getTotalCount() { return images.size(); } public boolean isEmpty() { return images.isEmpty(); } public void setImages(List<File> filteredImages) { this.images = filteredImages; this.currentPosition = 0; } }