From 7c72e94d8d64e5938ef62565a217492e67494d7f Mon Sep 17 00:00:00 2001 From: nathanpasdutout Date: Fri, 26 Sep 2025 11:16:47 +0200 Subject: [PATCH] DEV TP02 --- DEV/DEV3.1/TP02/.DS_Store | Bin 0 -> 6148 bytes .../Exercise1/Part2/ClickSwapImageEvent.java | 5 -- .../TP02/Exercise1/Part2/ImageWindow.java | 26 --------- DEV/DEV3.1/TP02/Exercise1/Part2/Main.java | 5 -- .../Part1/ClickSwapImageEvent.java | 0 .../{Exercise1 => }/Part1/ImageWindow.java | 0 .../TP02/{Exercise1 => }/Part1/Main.java | 0 .../Part2/ApprovedButtonPressedEvent.java | 19 ++++++ .../TP02/Part2/CancelButtonPressedEvent.java | 18 ++++++ .../TP02/Part2/ClickSwapImageEvent.java | 20 +++++++ .../TP02/Part2/CloseVerificationWindow.java | 37 ++++++++++++ DEV/DEV3.1/TP02/Part2/ImageWindow.java | 55 ++++++++++++++++++ DEV/DEV3.1/TP02/Part2/Main.java | 6 ++ DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java | 16 +++++ DEV/DEV3.1/TP02/Part2/start.sh | 3 + .../TP02/{Exercise1 => }/resources/dice.jpg | Bin .../TP02/{Exercise1 => }/resources/frog.png | Bin .../TP02/{Exercise1 => }/resources/random.jpg | Bin 18 files changed, 174 insertions(+), 36 deletions(-) create mode 100644 DEV/DEV3.1/TP02/.DS_Store delete mode 100644 DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java delete mode 100644 DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java delete mode 100644 DEV/DEV3.1/TP02/Exercise1/Part2/Main.java rename DEV/DEV3.1/TP02/{Exercise1 => }/Part1/ClickSwapImageEvent.java (100%) rename DEV/DEV3.1/TP02/{Exercise1 => }/Part1/ImageWindow.java (100%) rename DEV/DEV3.1/TP02/{Exercise1 => }/Part1/Main.java (100%) create mode 100644 DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java create mode 100644 DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java create mode 100644 DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java create mode 100644 DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java create mode 100644 DEV/DEV3.1/TP02/Part2/ImageWindow.java create mode 100644 DEV/DEV3.1/TP02/Part2/Main.java create mode 100644 DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java create mode 100755 DEV/DEV3.1/TP02/Part2/start.sh rename DEV/DEV3.1/TP02/{Exercise1 => }/resources/dice.jpg (100%) rename DEV/DEV3.1/TP02/{Exercise1 => }/resources/frog.png (100%) rename DEV/DEV3.1/TP02/{Exercise1 => }/resources/random.jpg (100%) diff --git a/DEV/DEV3.1/TP02/.DS_Store b/DEV/DEV3.1/TP02/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cc2a19f14d6e6bf46c834174a97a4171000eef9d GIT binary patch literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8zj35RBCIAV8Fop~hRD>C19@q>+&z$_^q@4UDsLbG} zKyGJc2w+HLC}JpKKz2VUXhIkm81(*w0oW@Dl}1QD1*zQ4z`$SuR`?&Rl9Qo`A(f$+ zA)ld?p@<y-V2PvytZkGS4S~@R7!85Z5Eu;snuh=*#0Cy-2t7)UhQMeD zjD`R_1VH730;Fxv-~go?AT&sdfsug$+y!7{U|@l1Vg&aC7(j9$tsokt6-0xyGBAQz zU^Bp485p5j8NuBUkUmgr8bpJ&GcbZ}2Jyk#85qGfGcYhhv@7S|8M|*m zbuFkqO@K;+>R?E9462w>8v#s^0YwR@Qc!gd(h8!%RWTz216b>5LjV>+qx5J9&_4tK DnCmi` literal 0 HcmV?d00001 diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java deleted file mode 100644 index 998a2ee..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java +++ /dev/null @@ -1,5 +0,0 @@ -package Part2; - -public class ClickSwapImageEvent { - -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java deleted file mode 100644 index b210479..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java +++ /dev/null @@ -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) { - } - } - } - } -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java b/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java deleted file mode 100644 index 57f8e1d..0000000 --- a/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -package Part2; - -public class Main { - -} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java rename to DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java b/DEV/DEV3.1/TP02/Part1/ImageWindow.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java rename to DEV/DEV3.1/TP02/Part1/ImageWindow.java diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/Main.java b/DEV/DEV3.1/TP02/Part1/Main.java similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/Part1/Main.java rename to DEV/DEV3.1/TP02/Part1/Main.java diff --git a/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java b/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java new file mode 100644 index 0000000..3fc07a4 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java @@ -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(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java b/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java new file mode 100644 index 0000000..d33ae82 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java @@ -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(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java new file mode 100644 index 0000000..09c8cb8 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java @@ -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(); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java b/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java new file mode 100644 index 0000000..96dce6d --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java @@ -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); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/ImageWindow.java b/DEV/DEV3.1/TP02/Part2/ImageWindow.java new file mode 100644 index 0000000..cb766f5 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/ImageWindow.java @@ -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); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/Main.java b/DEV/DEV3.1/TP02/Part2/Main.java new file mode 100644 index 0000000..6f93356 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + ImageWindow window = new ImageWindow(); + window.setVisible(true); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java b/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java new file mode 100644 index 0000000..87ffb18 --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java @@ -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); + } +} diff --git a/DEV/DEV3.1/TP02/Part2/start.sh b/DEV/DEV3.1/TP02/Part2/start.sh new file mode 100755 index 0000000..d50086b --- /dev/null +++ b/DEV/DEV3.1/TP02/Part2/start.sh @@ -0,0 +1,3 @@ +rm -rf *.class +javac Main.java +java Main \ No newline at end of file diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg b/DEV/DEV3.1/TP02/resources/dice.jpg similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg rename to DEV/DEV3.1/TP02/resources/dice.jpg diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/frog.png b/DEV/DEV3.1/TP02/resources/frog.png similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/frog.png rename to DEV/DEV3.1/TP02/resources/frog.png diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/random.jpg b/DEV/DEV3.1/TP02/resources/random.jpg similarity index 100% rename from DEV/DEV3.1/TP02/Exercise1/resources/random.jpg rename to DEV/DEV3.1/TP02/resources/random.jpg