fin des tp
This commit is contained in:
7
DEV3.1/organisation_du_code/galerie/Makefile
Normal file
7
DEV3.1/organisation_du_code/galerie/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
JC = javac
|
||||
JV = java
|
||||
|
||||
SRC = ./src
|
||||
BUILD = ./build
|
||||
RES = ./res
|
||||
|
||||
BIN
DEV3.1/organisation_du_code/galerie/res/Untitled.jpg
Normal file
BIN
DEV3.1/organisation_du_code/galerie/res/Untitled.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
DEV3.1/organisation_du_code/galerie/res/chat.jpg
Normal file
BIN
DEV3.1/organisation_du_code/galerie/res/chat.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
BIN
DEV3.1/organisation_du_code/galerie/res/hiboux.jpg
Normal file
BIN
DEV3.1/organisation_du_code/galerie/res/hiboux.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -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) {}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user