some changes

This commit is contained in:
2025-10-02 10:48:05 +02:00
parent 8b6d447574
commit 6ceeffac0e
14 changed files with 342 additions and 48 deletions

View File

@@ -10,11 +10,14 @@ public class ClickSwapImageEvent extends MouseAdapter {
}
public void mouseClicked(MouseEvent event) {
System.out.println(this.window.manager.cursor);
if(event.getX() > this.window.getWidth() / 2) {
this.window.nextImage();
System.out.println(this.window.manager.cursor);
return;
}
this.window.lastImage();
this.window.previousImage();
System.out.println(this.window.manager.cursor);
}
}

View File

@@ -0,0 +1,49 @@
import java.io.File;
import javax.swing.ImageIcon;
public class ImageManager {
private ImageIcon[] images;
public int cursor;
public ImageManager() {
File resourcesDirectory = new File("../resources/");
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
File[] files = resourcesDirectory.listFiles();
if(files != null) {
this.images = new ImageIcon[files.length];
this.cursor = 0;
for(File file : files) {
this.images[this.cursor] = new ImageIcon(file.getPath());
this.cursor++;
}
this.cursor = 0;
}
}
}
public ImageIcon getNextImage() {
if(this.cursor >= this.images.length - 1) {
this.cursor = 0;
} else {
this.cursor++;
}
return this.images[this.cursor];
}
public ImageIcon getPreviousImage() {
if(this.cursor <= 0) {
this.cursor = this.images.length - 1;
} else {
this.cursor--;
}
return this.images[this.cursor];
}
}

View File

@@ -1,86 +1,45 @@
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ImageWindow extends JFrame {
private ImageIcon[] images;
private int cursor;
public ImageManager manager;
private JLabel label;
public ImageWindow() {
this.manager = new ImageManager();
this.setSize(1024, 1024);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
File resourcesDirectory = new File("../resources/");
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
File[] files = resourcesDirectory.listFiles();
if(files != null) {
this.images = new ImageIcon[files.length];
this.cursor = 0;
for(File file : files) {
this.images[this.cursor] = new ImageIcon(file.getPath());
this.cursor++;
}
}
}
this.addMouseListener(new ClickSwapImageEvent(this));
this.cursor = 0;
this.nextImage();
}
public void nextImage() {
if(this.images.length == 0) return;
if(this.label != null) {
this.remove(this.label);
}
this.label = new JLabel(this.images[cursor]);
this.label = new JLabel(this.manager.getNextImage());
this.label.setVerticalAlignment(JLabel.CENTER);
this.label.setHorizontalAlignment(JLabel.CENTER);
if(this.cursor + 1 >= this.images.length) {
this.cursor = 0;
} else {
this.cursor++;
}
System.out.println(this.cursor);
this.add(label);
this.revalidate();
}
public void lastImage() {
if(this.images.length == 0) return;
public void previousImage() {
if(this.label != null) {
this.remove(this.label);
}
this.label = new JLabel(this.images[cursor]);
this.label = new JLabel(this.manager.getPreviousImage());
this.label.setVerticalAlignment(JLabel.CENTER);
this.label.setHorizontalAlignment(JLabel.CENTER);
if(this.cursor - 1 < 0) {
this.cursor = this.images.length - 1;
} else {
this.cursor--;
}
System.out.println(this.cursor);
this.add(label);
this.revalidate();
}