TP2 Terminé
39
DEV 3.1/TP2/Confirmation/Confirmation.java
Normal file
@ -0,0 +1,39 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Confirmation {
|
||||
|
||||
private static String[] paths = {
|
||||
"house", "info", "ok", "mail", "whatsapp"
|
||||
};
|
||||
|
||||
private static CardLayout cards;
|
||||
private static Container contentPane;
|
||||
|
||||
public static void next() {
|
||||
cards.next(contentPane);
|
||||
}
|
||||
|
||||
public static void previous() {
|
||||
cards.previous(contentPane);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame window = new JFrame("GalerieAlt");
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setSize(700, 700);
|
||||
window.setLocation(200, 200);
|
||||
window.addWindowListener(new ConfirmationWListener());
|
||||
window.setVisible(true);
|
||||
|
||||
contentPane = window.getContentPane();
|
||||
cards = new CardLayout();
|
||||
contentPane.setLayout(cards);
|
||||
|
||||
for (String path : paths) {
|
||||
JLabel label = new JLabel(new ImageIcon("./images/" + path + ".png"));
|
||||
label.addMouseListener(new ConfirmationMListener());
|
||||
contentPane.add(label, path);
|
||||
}
|
||||
}
|
||||
}
|
43
DEV 3.1/TP2/Confirmation/ConfirmationMListener.java
Normal file
@ -0,0 +1,43 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class ConfirmationMListener implements MouseListener {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
JLabel source = (JLabel)e.getSource();
|
||||
int x = e.getX();
|
||||
|
||||
if (x > source.getWidth() / 2) {
|
||||
Confirmation.next();
|
||||
} else {
|
||||
Confirmation.previous();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
75
DEV 3.1/TP2/Confirmation/ConfirmationWListener.java
Normal file
@ -0,0 +1,75 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* GalleryWListener
|
||||
*/
|
||||
public class ConfirmationWListener implements WindowListener {
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
JFrame window = (JFrame)e.getSource();
|
||||
JDialog d = new JDialog(window, true);
|
||||
DialogListener dl = new DialogListener(d);
|
||||
|
||||
d.setTitle("aRE U SUR");
|
||||
d.setSize(300, 200);
|
||||
d.setLocation(500, 500);
|
||||
d.setLayout(new GridLayout(1, 2));
|
||||
JButton yesBT = new JButton("Oui");
|
||||
yesBT.setName("Oui");
|
||||
yesBT.addMouseListener(dl);
|
||||
JButton noBT = new JButton("Non");
|
||||
noBT.setName("Non");
|
||||
noBT.addMouseListener(dl);
|
||||
|
||||
d.add(yesBT);
|
||||
d.add(noBT);
|
||||
d.setVisible(true);
|
||||
|
||||
if (dl.getShouldClose()) {
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
} else {
|
||||
window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
54
DEV 3.1/TP2/Confirmation/DialogListener.java
Normal file
@ -0,0 +1,54 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class DialogListener implements MouseListener {
|
||||
|
||||
private JDialog d;
|
||||
private boolean shouldClose = false;
|
||||
|
||||
public DialogListener(JDialog d) {
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Component c = (Component)e.getSource();
|
||||
|
||||
if (c.getName() == "Oui") {
|
||||
shouldClose = true;
|
||||
d.dispose();
|
||||
} else if (c.getName() == "Non") {
|
||||
shouldClose = false;
|
||||
d.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getShouldClose() {
|
||||
return this.shouldClose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
BIN
DEV 3.1/TP2/Confirmation/images/house.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
DEV 3.1/TP2/Confirmation/images/info.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
DEV 3.1/TP2/Confirmation/images/mail.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
DEV 3.1/TP2/Confirmation/images/ok.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
DEV 3.1/TP2/Confirmation/images/whatsapp.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
DEV 3.1/TP2/Galerie/Galerie.class
Normal file
39
DEV 3.1/TP2/Galerie/Galerie.java
Normal file
@ -0,0 +1,39 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Galerie {
|
||||
|
||||
private static String[] paths = {
|
||||
"house", "info", "ok", "mail", "whatsapp"
|
||||
};
|
||||
|
||||
private static int count = -1;
|
||||
private static JLabel lb;
|
||||
private static JFrame window;
|
||||
|
||||
public static void update(boolean increment) {
|
||||
count += increment ? 1 : -1;
|
||||
if (count == -1) {
|
||||
count = paths.length-1;
|
||||
}
|
||||
count %= paths.length;
|
||||
|
||||
if (lb != null) window.remove(lb);
|
||||
|
||||
String path = "./images/" + paths[count] + ".png";
|
||||
lb = new JLabel(new ImageIcon(path));
|
||||
lb.addMouseListener(new GalleryListener());
|
||||
window.add(lb, BorderLayout.CENTER);
|
||||
window.revalidate();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
window = new JFrame("Galerie");
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setSize(650, 650);
|
||||
window.setLocation(200, 200);
|
||||
window.setVisible(true);
|
||||
|
||||
Galerie.update(true);
|
||||
}
|
||||
}
|
BIN
DEV 3.1/TP2/Galerie/GalerieAlt.class
Normal file
38
DEV 3.1/TP2/Galerie/GalerieAlt.java
Normal file
@ -0,0 +1,38 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GalerieAlt {
|
||||
|
||||
private static String[] paths = {
|
||||
"house", "info", "ok", "mail", "whatsapp"
|
||||
};
|
||||
|
||||
private static CardLayout cards;
|
||||
private static Container contentPane;
|
||||
|
||||
public static void next() {
|
||||
cards.next(contentPane);
|
||||
}
|
||||
|
||||
public static void previous() {
|
||||
cards.previous(contentPane);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame window = new JFrame("GalerieAlt");
|
||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
window.setSize(700, 700);
|
||||
window.setLocation(200, 200);
|
||||
window.setVisible(true);
|
||||
|
||||
contentPane = window.getContentPane();
|
||||
cards = new CardLayout();
|
||||
contentPane.setLayout(cards);
|
||||
|
||||
for (String path : paths) {
|
||||
JLabel label = new JLabel(new ImageIcon("./images/" + path + ".png"));
|
||||
label.addMouseListener(new GalleryAltListener());
|
||||
contentPane.add(label, path);
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV 3.1/TP2/Galerie/GalleryAltListener.class
Normal file
43
DEV 3.1/TP2/Galerie/GalleryAltListener.java
Normal file
@ -0,0 +1,43 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GalleryAltListener implements MouseListener {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
JLabel source = (JLabel)e.getSource();
|
||||
int x = e.getX();
|
||||
|
||||
if (x > source.getWidth() / 2) {
|
||||
GalerieAlt.next();
|
||||
} else {
|
||||
GalerieAlt.previous();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
BIN
DEV 3.1/TP2/Galerie/GalleryListener.class
Normal file
39
DEV 3.1/TP2/Galerie/GalleryListener.java
Normal file
@ -0,0 +1,39 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class GalleryListener implements MouseListener {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
JLabel source = (JLabel)e.getSource();
|
||||
int x = e.getX();
|
||||
|
||||
Galerie.update(x > source.getWidth() / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
BIN
DEV 3.1/TP2/Galerie/images/house.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
DEV 3.1/TP2/Galerie/images/info.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
DEV 3.1/TP2/Galerie/images/mail.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
DEV 3.1/TP2/Galerie/images/ok.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
DEV 3.1/TP2/Galerie/images/whatsapp.png
Normal file
After Width: | Height: | Size: 10 KiB |