This commit is contained in:
2025-09-26 11:16:47 +02:00
parent a9782efcdd
commit 7c72e94d8d
18 changed files with 174 additions and 36 deletions

BIN
DEV/DEV3.1/TP02/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -1,5 +0,0 @@
package Part2;
public class ClickSwapImageEvent {
}

View File

@@ -1,26 +0,0 @@
import java.io.File;
import java.awt.CardLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class ImageWindow extends JFrame {
private CardLayout card;
public ImageWindow() {
this.card = new CardLayout();
File resourcesDirectory = new File("../resources/");
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
File[] files = resourcesDirectory.listFiles();
if(files != null) {
for(File file : files) {
}
}
}
}
}

View File

@@ -1,5 +0,0 @@
package Part2;
public class Main {
}

View File

@@ -0,0 +1,19 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
public class ApprovedButtonPressedEvent implements ActionListener{
private JDialog dialog;
public ApprovedButtonPressedEvent(JDialog dialog) {
this.dialog = dialog;
}
@Override
public void actionPerformed(ActionEvent event) {
this.dialog.dispose();
this.dialog.getOwner().dispose();
}
}

View File

@@ -0,0 +1,18 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDialog;
public class CancelButtonPressedEvent implements ActionListener{
private JDialog dialog;
public CancelButtonPressedEvent(JDialog dialog) {
this.dialog = dialog;
}
@Override
public void actionPerformed(ActionEvent event) {
this.dialog.dispose();
}
}

View File

@@ -0,0 +1,20 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class ClickSwapImageEvent extends MouseAdapter {
private ImageWindow window;
public ClickSwapImageEvent(ImageWindow window) {
this.window = window;
}
public void mouseClicked(MouseEvent event) {
if(event.getX() > this.window.getWidth() / 2) {
this.window.nextImage();
return;
}
this.window.lastImage();
}
}

View File

@@ -0,0 +1,37 @@
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class CloseVerificationWindow extends JDialog {
public CloseVerificationWindow(ImageWindow parent) {
super(parent, true);
this.setSize(parent.getWidth() / 3, parent.getHeight() / 3);
this.setLocationRelativeTo(parent);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.setLayout(new GridLayout(2, 1));
JLabel text = new JLabel("Are you sure you want to close the window?");
text.setVerticalAlignment(JLabel.CENTER);
text.setHorizontalAlignment(JLabel.CENTER);
this.add(text);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JButton approveButton = new JButton("Yes");
approveButton.addActionListener(new ApprovedButtonPressedEvent(this));
panel.add(approveButton, BorderLayout.WEST);
JButton cancelButton = new JButton("No");
cancelButton.addActionListener(new CancelButtonPressedEvent(this));
panel.add(cancelButton, BorderLayout.EAST);
this.add(panel);
}
}

View File

@@ -0,0 +1,55 @@
import java.io.File;
import java.awt.CardLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ImageWindow extends JFrame {
private CardLayout cards;
private JPanel imagePanel;
public ImageWindow() {
this.setSize(1024, 1024);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
File resourcesDirectory = new File("../resources/");
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
File[] files = resourcesDirectory.listFiles();
if(files != null) {
this.cards = new CardLayout();
this.imagePanel = new JPanel();
this.imagePanel.setLayout(this.cards);
for(File file : files) {
JLabel label = new JLabel(new ImageIcon(file.getPath()));
label.setHorizontalAlignment(JLabel.CENTER);
label.setVerticalAlignment(JLabel.CENTER);
this.imagePanel.add(new JLabel(new ImageIcon(file.getPath())), file.getName());
}
this.add(this.imagePanel);
this.addMouseListener(new ClickSwapImageEvent(this));
this.addWindowListener(new WindowClosedEvent(this));
this.nextImage();
}
}
}
public void nextImage() {
this.cards.next(this.imagePanel);
}
public void lastImage() {
this.cards.previous(this.imagePanel);
}
}

View File

@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
ImageWindow window = new ImageWindow();
window.setVisible(true);
}
}

View File

@@ -0,0 +1,16 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class WindowClosedEvent extends WindowAdapter {
private ImageWindow window;
public WindowClosedEvent(ImageWindow window) {
this.window = window;
}
@Override
public void windowClosing(WindowEvent event) {
(new CloseVerificationWindow(this.window)).setVisible(true);
}
}

3
DEV/DEV3.1/TP02/Part2/start.sh Executable file
View File

@@ -0,0 +1,3 @@
rm -rf *.class
javac Main.java
java Main

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB