TP2 Terminé

This commit is contained in:
HORVILLE 2022-09-14 11:01:07 +02:00
parent 5495b60332
commit 781fda9f71
22 changed files with 370 additions and 0 deletions

View 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);
}
}
}

View 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
}
}

View 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
}
}

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

View 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);
}
}

Binary file not shown.

View 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);
}
}
}

Binary file not shown.

View 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
}
}

Binary file not shown.

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB