fin des tp

This commit is contained in:
2024-10-17 12:16:23 +02:00
parent 6e4a3d85d0
commit 26338467c0
22 changed files with 470 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class Boutons implements WindowListener{
@Override
public void windowClosing(WindowEvent evenement){
int confirmed=JOptionPane(null,"Voulez-vous fermer l'application ?","Confirmation de fermeture",JOptionPane.YES_NO_OPTION);
if (confirmed==JOptionPane.YES_OPTION){
evenement.dispose();
}
}
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setSize(500, 300);
fenetre.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
GridBagConstraints c = new GridBagConstraints();
fenetre.setLayout(new GridBagLayout());
c.fill=GridBagConstraints.BOTH;
JButton etiquette = new JButton("1");
c.gridx=0;
c.gridy=0;
c.gridwidth=2;
c.gridheight=1;
c.weightx=1;
c.weighty=1;
fenetre.add(etiquette,c);
JButton etiquette1 = new JButton("2");
c.gridx=2;
c.gridy=0;
c.gridwidth=1;
c.gridheight=2;
c.weightx=1;
c.weighty=1;
fenetre.add(etiquette1,c);
JButton etiquette2 = new JButton("3");
c.gridx=1;
c.gridy=2;
c.gridwidth=2;
c.gridheight=1;
c.weightx=1;
c.weighty=1;
fenetre.add(etiquette2,c);
JButton etiquette3 = new JButton("4");
c.gridx=0;
c.gridy=1;
c.gridwidth=1;
c.gridheight=2;
c.weightx=1;
c.weighty=1;
fenetre.add(etiquette3,c);
JButton etiquette4 = new JButton("5");
c.gridx=1;
c.gridy=1;
c.gridwidth=1;
c.gridheight=1;
c.weightx=0;
c.weighty=0;
fenetre.add(etiquette4,c);
fenetre.setVisible(true);
fenetre.addMouseListener(this);
}
}

View File

@@ -0,0 +1,7 @@
JC = javac
JV = java
SRC = ./src
BUILD = ./build
RES = ./res

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,59 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Controller_galerie implements MouseListener{
private int indice;
private int max_indice;
private String[] tab;
private JFrame page;
private JLabel image;
public Controller_galerie(String[] tab){
this.tab = tab;
this.indice = 0;
this.max_indice = this.tab.length-1;
}
public void SetPage(JFrame page, JLabel image){
this.page = page;
this.image = image;
}
@Override
public void mouseClicked(MouseEvent e) {
Component taille = (Component) e.getComponent();
if (e.getX()>taille.getWidth()/2){
if (this.indice == this.max_indice){
this.indice = 0;
}else{
this.indice++;
}
}else if (e.getX()<taille.getWidth()/2){
if (this.indice == 0){
this.indice = this.max_indice;
}else{
this.indice--;
}
}
System.out.println(this.indice);
System.out.println(taille.getWidth()/2);
this.page.remove(this.image);
this.image = new JLabel(new ImageIcon(this.tab[this.indice]));
this.image.addMouseListener(this);
this.page.add(this.image);
this.page.revalidate();
}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
}

View File

@@ -0,0 +1,11 @@
import javax.swing.*;
import java.awt.*;
public class Galerie{
public static void main(String[] args){
String[] tab = {"Untitled.jpg", "chat.jpg", "hiboux.jpg"};
Controller_galerie controller = new Controller_galerie(tab);
View_galerie vue = new View_galerie();
vue.affichage(tab[0],controller);
}
}

View File

@@ -0,0 +1,15 @@
import javax.swing.*;
import java.awt.*;
public class View_galerie{
public void affichage(String nom, Controller_galerie controller){
JFrame fenetre = new JFrame();
fenetre.setSize(500, 300);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel image = new JLabel(new ImageIcon(nom));
controller.SetPage(fenetre,image);
image.addMouseListener(controller);
fenetre.add(image);
fenetre.setVisible(true);
}
}