DEV TP02
This commit is contained in:
BIN
DEV/DEV3.1/TP02/.DS_Store
vendored
Normal file
BIN
DEV/DEV3.1/TP02/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,5 +0,0 @@
|
|||||||
package Part2;
|
|
||||||
|
|
||||||
public class ClickSwapImageEvent {
|
|
||||||
|
|
||||||
}
|
|
@@ -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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
package Part2;
|
|
||||||
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
}
|
|
19
DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java
Normal file
19
DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
18
DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java
Normal file
18
DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
20
DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java
Normal file
20
DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
37
DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java
Normal file
37
DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
55
DEV/DEV3.1/TP02/Part2/ImageWindow.java
Normal file
55
DEV/DEV3.1/TP02/Part2/ImageWindow.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
6
DEV/DEV3.1/TP02/Part2/Main.java
Normal file
6
DEV/DEV3.1/TP02/Part2/Main.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ImageWindow window = new ImageWindow();
|
||||||
|
window.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
16
DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java
Normal file
16
DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java
Normal 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
3
DEV/DEV3.1/TP02/Part2/start.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
rm -rf *.class
|
||||||
|
javac Main.java
|
||||||
|
java Main
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Reference in New Issue
Block a user