| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 
 | import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.util.*;
 
public class InterfaceFax extends JFrame implements ActionListener{
    private JPanel haut = new JPanel();
    private JLabel bas = new JLabel();  // 
    private JButton precedent = new JButton(new ImageIcon("images/Précédent.gif")); 
    private JButton suivant = new JButton(new ImageIcon("images/Suivant.gif")); 
    private JButton supprimer = new JButton(new ImageIcon("images/Supprimer.gif"));
    private JButton quitter = new JButton(new ImageIcon("images/exit.gif"));
    private JLabel nomFournisseur = new JLabel("Nom du fournisseur :");
    private JTextField nom = new JTextField(12);
    private JButton enregistrer = new JButton("Enregistrer");
    private ArrayList<ImageIcon> images = new ArrayList<ImageIcon>();
    private ArrayList<File> file;
 
    //indice pour désigner l'image courante
    private int indiceImage = 0;
 
    public InterfaceFax(){
        super("Gestion des fax");
 
 
        initImage(); 
 
        initComposants();
        this.setSize(500, 500);
        this.setResizable(false);
        this.setVisible(true);
 
    }
 
    //Rempli un tableau d'images
    private void initImage() {
         File[] tabImages = new File("test").listFiles();
        for(File fichier : tabImages) {
        	if(fichier.toString().substring(fichier.toString().lastIndexOf('.')).equalsIgnoreCase(".jpg")){
            ImageIcon image = new ImageIcon(fichier.getAbsolutePath());
 
            images.add(image); 
        	}
        	if(fichier.toString().substring(fichier.toString().lastIndexOf('.')).equalsIgnoreCase(".jpeg")){
                ImageIcon image = new ImageIcon(fichier.getAbsolutePath());
 
                images.add(image); 
            	}
        }
 
 
        file = new ArrayList<File>();
        for(int i = 0; i < tabImages.length; i++)
        {
        	file.add(tabImages[i]);
        }
 
        if(images.size() > 0)
        {
        	JOptionPane.showMessageDialog(null, "Vous avez présentement " + file.size() + "  fax.");
    		bas.setIcon(images.get(0));
        }
        else
        {
        	precedent.setEnabled(false);
        	suivant.setEnabled(false);
        	supprimer.setEnabled(false);
        	bas.setText("Vous n'avez aucun fax !");
        }
    }
 
 
 
    public void initComposants(){
 
        //Pour centrer les images
    	bas.setHorizontalAlignment(JLabel.CENTER);
    	bas.setVerticalAlignment(JLabel.CENTER);
 
    	//Pour afficher la première image
    	if(images.size() > 0)
    		bas.setIcon(images.get(0));
 
 
 
 
 
        precedent.addActionListener(this);
        precedent.setMargin(new Insets(0,0,0,0)); 
        haut.add(precedent);
 
        suivant.addActionListener(this);
        suivant.setMargin(new Insets(0,0,0,0));
        haut.add(suivant);
 
        supprimer.addActionListener(this);
        supprimer.setMargin(new Insets(0,0,0,0));
        haut.add(supprimer);
 
        quitter.addActionListener(this);
        quitter.setMargin(new Insets(0,0,0,0));
        haut.add(quitter);
 
        haut.add(nomFournisseur);
        nomFournisseur.setForeground(Color.WHITE);
        haut.add(nom);
        haut.add(enregistrer);
 
        haut.setBackground(Color.BLACK);
 
 
        add(haut, BorderLayout.NORTH);
        add(bas, BorderLayout.CENTER); 
    }
 
    private void changerImage() {
        if(indiceImage < 0)
        {
        	bas.setIcon(null);
                indiceImage = images.size() - 1;
        }
        if(indiceImage >= images.size())
                indiceImage = 0;
 
        if(indiceImage >= 0)
        {
        	bas.setIcon(images.get(indiceImage));
        }
        else
        {
        	bas.setText("Il ne reste plus aucuns fax à visionner");
        	supprimer.setEnabled(false);
        	precedent.setEnabled(false);
        	suivant.setEnabled(false);
        }
    }
 
 
 
    public void actionPerformed(ActionEvent e){
 
        if(e.getSource() == precedent ){
            indiceImage--;
            changerImage();
 
        }
        else if(e.getSource() == suivant) {
            indiceImage++;
            changerImage();
 
        }
        else if(e.getSource() == supprimer){
        	images.remove(indiceImage);
        	file.get(indiceImage).delete();
        	indiceImage--;
 
        	changerImage();
        }
        else if(e.getSource() == quitter){
        	System.exit(0);
        }
    }
 
    public static void main(String[] args){
        InterfaceFax fax = new InterfaceFax();
        fax.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
} | 
Partager