IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques en Java Discussion :

Problème de mise à jour affichage slideshow images dans un JPanel


Sujet :

Interfaces Graphiques en Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 7
    Points : 4
    Points
    4
    Par défaut Problème de mise à jour affichage slideshow images dans un JPanel
    Bonjour à tous,

    Je suis un débutant en Java et je réalise un petit projet qui consiste à afficher des images de plantes avec JComBox à partir d'une base de données MySQL et un JLabel pour afficher un diaporama d'images.

    Pour les images, je dois les importer dans un dossier local src/... et pour cela j'utilise une méthode byteArrayOutputStream qui fonctionne bien.

    Lorsque je sélectionne un élément de la liste pour la première fois, les images sont bien affichées dans le JLabel et le silideshow fonctionne bien avec les boutons.

    Par contre lorsque je change de sélection dans ma liste, mes informations sont bien changées dans les différents JTextField mais ce sont toujours les mêmes images de la première sélection qui sont affichées dans mon diaporama et pourtant elles sont bien changées dans le fichier source.

    Voici mon code avec la classe constructeur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    package com.dug.plantId;
     
    /*** Constructor images DB ***/
     
    public class Plant {
     
        String id;
        byte[] image1, image2, image3, image4, image5;
     
        public Plant(
            byte[] image1, byte[] image2, byte[] image3, byte[] image4, byte[] image5, String id) {}
     
        public String getId() {
            return id;
        }
     
        public void setId(String id) {
            this.id = id;
        }
     
        public byte[] getImage1() {
            return image1;
        }
     
        public void setImage1(byte[] image1) {
            this.image1 = image1;
        }
     
        public byte[] getImage2() {
            return image2;
        }
     
        public void setImage2(byte[] image2) {
            this.image2 = image2;
        }
     
        public byte[] getImage3() {
            return image3;
        }
     
        public void setImage3(byte[] image3) {
            this.image3 = image3;
        }
     
        public byte[] getImage4() {
            return image4;
        }
     
        public void setImage4(byte[] image4) {
            this.image4 = image4;
        }
     
        public byte[] getImage5() {
            return image5;
        }
     
        public void setImage5(byte[] image5) {
            this.image5 = image5;
        }
    }
    Classe avec le code pour la connexion à la DB et l'enregistrement des images dans un dossier (src)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    170
    171
    172
    173
    174
    175
    176
    package com.dug.plantId;
     
    import java.io.*;
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.List;
     
    public class DBConnection {
     
            private Connection connetion = null;
        private Statement stmt = null;
        private ResultSet rs = null;
     
        private MyPanels DBConnection;
     
        /*** Connexion à MySQL ***/
     
        public DBConnection() {
            try {
                this.connetion = DriverManager.getConnection("jdbc:mysql://localhost/dbarbres?" +
                    "user=Dug&password=Java427");
            } catch (SQLException ex) {
                // handle any errors
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            }
        }
     
        /***  Méthode pour créer une liste importée de la BD ***/
     
        public List<Plant> searchPlant(String nom) {
            List<Plant> listPlants = new ArrayList<Plant> ();
            try {
                stmt = connetion.createStatement();
                rs = stmt.executeQuery("SELECT * FROM dbarbres.tblarbre where nomLatin like '%" + nom + "%' or nomCommun like '%" + nom + "%'");
                byte[] image = null;
     
                while (rs.next()) {
                    listPlants.add(new Plant(rs.getBytes("image1"), rs.getBytes("image2"),
                        rs.getBytes("image3"), rs.getBytes("image4"), rs.getBytes("image5"), rs.getInt("id") + ""));
     
                    /***  Appel des méthodes de FileOutputStream pour afficher les images de la BD. ***/
     
                    image1Generate();
                    image2Generate();
                    image3Generate();
                    image4Generate();
                    image5Generate();
                    MyPanels.imagesImportToList();
     
                    /***  Appelez une méthode statique pour afficher la première image ***/
     
                    MyPanels.displayImage1();
                }
            } catch (SQLException ex) {
                // handle any errors
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
     
            }
            return listPlants;
        }
     
        /***  Méthodes pour générer des images de bases de données MySQL dans un dossier local (src) ***/
     
        public void image1Generate() throws SQLException, IOException {
     
            int i = rs.getInt("id");
            Blob ph = rs.getBlob("image1");
            if (ph == null) {
                return;
            }
            int length = (int) ph.length();
            int bufferSize = 1024;
            InputStream in = ph.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputStream outputStream = new FileOutputStream("src/photos/photo1.jpg");
            byte[] buffer = new byte[bufferSize];
     
            while ((length = in .read(buffer)) != -1) {
                System.out.println("writing " + length + " bytes");
                out.write(buffer, 0, length);
            }
            out.writeTo(outputStream); in .close();
        }
     
        public void image2Generate() throws SQLException, IOException {
     
            int i = rs.getInt("id");
            Blob ph = rs.getBlob("image2");
            if (ph == null) {
                return;
            }
            int length = (int) ph.length();
            int bufferSize = 1024;
            InputStream in = ph.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputStream outputStream = new FileOutputStream("src/photos/photo2.jpg");
            byte[] buffer = new byte[bufferSize];
            while ((length = in .read(buffer)) != -1) {
                System.out.println("writing " + length + " bytes");
                out.write(buffer, 0, length);
            }
            out.writeTo(outputStream); in .close();
        }
     
        public void WindowsMainPanelsAffichage() {
            DBConnection affichageImage = new DBConnection();
            affichageImage.DBConnection = new MyPanels();
        }
     
        public void image3Generate() throws SQLException, IOException {
     
            int i = rs.getInt("id");
            Blob ph = rs.getBlob("image3");
            if (ph == null) {
                return;
            }
            int length = (int) ph.length();
            int bufferSize = 1024;
            InputStream in = ph.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputStream outputStream = new FileOutputStream("src/photos/photo3.jpg");
            byte[] buffer = new byte[bufferSize];
            while ((length = in .read(buffer)) != -1) {
                System.out.println("writing " + length + " bytes");
                out.write(buffer, 0, length);
            }
            out.writeTo(outputStream); in .close();
        }
     
        public void image4Generate() throws SQLException, IOException {
     
            int i = rs.getInt("id");
            Blob ph = rs.getBlob("image4");
            if (ph == null) {
                return;
            }
            int length = (int) ph.length();
            int bufferSize = 1024;
            InputStream in = ph.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputStream outputStream = new FileOutputStream("src/photos/photo4.jpg");
            byte[] buffer = new byte[bufferSize];
            while ((length = in .read(buffer)) != -1) {
                System.out.println("writing " + length + " bytes");
                out.write(buffer, 0, length);
            }
            out.writeTo(outputStream); in .close();
        }
     
        public void image5Generate() throws SQLException, IOException {
     
            int i = rs.getInt("id");
            Blob ph = rs.getBlob("image5");
            if (ph == null) {
                return;
            }
            int length = (int) ph.length();
            int bufferSize = 1024;
            InputStream in = ph.getBinaryStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            OutputStream outputStream = new FileOutputStream("src/photos/photo5.jpg");
            byte[] buffer = new byte[bufferSize];
            while ((length = in .read(buffer)) != -1) {
                System.out.println("writing " + length + " bytes");
                out.write(buffer, 0, length);
            }
            out.writeTo(outputStream); in .close();
        }
    }
    Classe avec code pour générer des cadres, des panneaux, des jlabel pour les images et des boutons pour le diaporama.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    package com.dug.plantId;
     
    import javax.swing.*;
    import javax.swing.border.Border;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.List;
     
    public class MyPanels extends JPanel implements ActionListener {
     
        private JComboBox jComboBoxNomCommun;
        private JComboBox jComboBoxNomLatin;
     
        static ImageIcon[] s;
        static JLabel jLabelImages;
        private static JButton b1;
        private static JButton b2;
        int i, l1;
     
        public MyPanels() {
            super();
            initComposantsPanel1();
        }
     
        /****  main ****/
     
        public static void main(String args[]) {
     
            MyPanels launchWindowsProg = new MyPanels();
            launchWindowsProg.generatePanels();
            launchWindowsProg.buttonsSlideShow();
        }
     
        /***  Initialiser les composants de panel1. ***/
     
        private void initComposantsPanel1() {
     
            this.setLayout(new GridBagLayout());
     
     
            JLabel listeAlphabetiqueNomLatin = panel1LabelCell(GridBagConstraints.WEST, 2, 1, "Liste alphabétique nom latin: ");
            jComboBoxNomLatin = panel1ComboBoxNomLatin(GridBagConstraints.WEST, 3, 1, "");
     
     
            JLabel listeAlphabetiqueNomCommunTextField = panel1LabelCell(GridBagConstraints.WEST, 2, 2, "Liste alphabétique nom commun: ");
            jComboBoxNomCommun = panel1ComboBoxNomCommun(GridBagConstraints.WEST, 3, 2, "");
        }
     
        /*** Constructeurs pour les différents composants ***/
     
        public JLabel panel1LabelCell(int GridBagConstraints, int positionGridx, int positionGridy, String labelLigne) {
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.insets = new Insets(0, 300, 3, 20);
            gridBagConstraints.anchor = GridBagConstraints;
            gridBagConstraints.gridx = positionGridx;
            gridBagConstraints.gridy = positionGridy;
            JLabel jLabel = new JLabel(labelLigne);
            this.add(jLabel, gridBagConstraints);
            return jLabel;
        }
     
        /*** Constructeur  panel1 (JComboBox) ***/
     
        public JComboBox panel1ComboBoxNomCommun(int GridBagConstraints, int positionGridx, int positionGridy, String text) {
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.anchor = GridBagConstraints;
            gridBagConstraints.ipadx = 10;
            JComboBox jComboBoxNomCommun = new JComboBox();
            jComboBoxNomCommun.setPreferredSize(new Dimension(225, 23));
            gridBagConstraints.gridx = positionGridx;
            gridBagConstraints.gridy = positionGridy;
     
            /*** DB connection ***/
     
            Connection con = null;
            Statement st = null;
            ResultSet rs = null;
     
            /*** Import liste DB vers jComboBoxNomCommun ***/
     
            try {
                con = DriverManager.getConnection("jdbc:mysql://localhost/dbarbres?" +
                    "user=Dug&password=Java427");
                st = con.createStatement();
                String s = "select * from tblarbre";
                rs = st.executeQuery(s);
                while (rs.next()) {
                    jComboBoxNomCommun.addItem(rs.getString(
                        "nomCommun"));
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "ERROR");
            } finally {
                try {
                    st.close();
                    rs.close();
                    con.close();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "ERROR CLOSE");
                }
            }
     
            jComboBoxNomCommun.addActionListener(e -> {
     
                String typedText = ((JTextField) jComboBoxNomCommun.getEditor().getEditorComponent()).getText();
     
                DBConnection dBConnection = new DBConnection();
                List<Plant> findedPlant = dBConnection.searchPlant(typedText);
     
                for (Plant plant: findedPlant) {
     
                }
            });
            this.add(jComboBoxNomCommun, gridBagConstraints);
            return jComboBoxNomCommun;
        }
        private JComboBox panel1ComboBoxNomLatin(int GridBagConstraints, int positionGridx, int positionGridy, String text) {
            GridBagConstraints gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.anchor = GridBagConstraints;
            gridBagConstraints.ipadx = 10;
            JComboBox jComboBoxNomLatin = new JComboBox();
            jComboBoxNomLatin.setPreferredSize(new Dimension(225, 23));
            gridBagConstraints.gridx = positionGridx;
            gridBagConstraints.gridy = positionGridy;
            this.add(jComboBoxNomLatin, gridBagConstraints);
     
            Connection con = null;
            Statement st = null;
            ResultSet rs = null;
     
            /***  Import liste DB to jComboBoxNomLatin ***/
     
            try {
                con = DriverManager.getConnection("jdbc:mysql://localhost/dbarbres?" +
                    "user=Dug&password=Java427");
                st = con.createStatement();
                String s = "select * from tblarbre";
                rs = st.executeQuery(s);
                while (rs.next()) {
                    jComboBoxNomLatin.addItem(rs.getString(
                        "nomLatin"));
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "ERROR");
            } finally {
                try {
                    st.close();
                    rs.close();
                    con.close();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "ERROR CLOSE");
                }
            }
            jComboBoxNomLatin.addActionListener(e -> {
     
                String typedText = ((JTextField) jComboBoxNomLatin.getEditor().getEditorComponent()).getText();
     
                DBConnection dBConnection = new DBConnection();
                List<Plant> findedPlant = dBConnection.searchPlant(typedText);
     
                for (Plant plant: findedPlant) {
                }
            });
            return jComboBoxNomLatin;
        }
     
        /*** Generer les panels ***/
     
        void generatePanels() {
            SwingUtilities.invokeLater(() -> {
                JFrame frame = new JFrame();
                frame.setLayout(new BorderLayout());
                JPanel panel1 = new JPanel();
                JPanel panel2 = new JPanel();
                Border border = BorderFactory.createLineBorder(Color.GRAY, 1);
                panel1.setBounds(10, 10, 1400, 200);
                panel2.setBounds(720, 250, 700, 530);
                panel2.setBorder(border);
                MyPanels myPanels = new MyPanels();
                panel1.add(myPanels);
                frame.add(panel1, BorderLayout.NORTH);
                frame.add(panel2, BorderLayout.EAST);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(null);
                frame.setSize(1450, 900);
                frame.setVisible(true);
     
                /*** Ajout des buttons pour showview images***/
     
                panel2.add(b1);
                panel2.add(b2);
                jLabelImages = new JLabel("", JLabel.CENTER);
                panel2.add(jLabelImages, BorderLayout.CENTER);
            });
        }
     
        /*** Import images dans une liste***/
     
        public static void imagesImportToList() {
            s = new ImageIcon[5];
            s[0] = new ImageIcon("src/photos/photo1.jpg");
            s[1] = new ImageIcon("src/photos/photo2.jpg");
            s[2] = new ImageIcon("src/photos/photo3.jpg");
            s[3] = new ImageIcon("src/photos/photo4.jpg");
            s[4] = new ImageIcon("src/photos/photo5.jpg");
        }
        /***  Méthode d'affichage des images du diaporama ***/
     
        public void buttonsSlideShow() {
     
            b1 = new JButton("<<");
            b2 = new JButton(">>");
     
            b1.addActionListener(e -> {
                if (e.getSource() == b1) {
                    if (i == 0) {
                        JOptionPane.showMessageDialog(null, " First image");
                    } else {
                        i = i - 1;
                        jLabelImages.setIcon(s[i]);
                    }
                }
                if (e.getSource() == b2) {
                    if (i == s.length - 1) {
                        JOptionPane.showMessageDialog(null, "Last Image");
                    } else {
                        i = i + 1;
                        jLabelImages.setIcon(s[i]);
                    }
                }
            });
            b2.addActionListener(e -> {
                if (e.getSource() == b1) {
                    if (i == 0) {
                        JOptionPane.showMessageDialog(null, "First image");
                    } else {
                        i = i - 1;
                        jLabelImages.setIcon(s[i]);
                    }
                }
                if (e.getSource() == b2) {
                    if (i == s.length - 1) {
                        JOptionPane.showMessageDialog(null, "Last Image");
                    } else {
                        i = i + 1;
                        jLabelImages.setIcon(s[i]);
                    }
                }
            });
        }
        @Override
        public void actionPerformed(ActionEvent e) {}
     
        /*** Afficher l'image1 après la séléction dans la liste JCombobox  ***/
     
        static void displayImage1() {
            String displayImage1 = "src/photos/photo1.jpg";
            ImageIcon image1 = new ImageIcon(displayImage1);
            jLabelImages.setIcon(image1);
        }
    }
    J'ai tout essayé mais je n'y arrive pas, il y aurait peut-être une solution avec ressource intégrée via une URL. Une URL qui peut être obtenue en utilisant Class.getResource() mais je n'ai pas assez de connaissances.

    Merci d'avance pour votre éclairage.

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 838
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 838
    Points : 22 846
    Points
    22 846
    Billets dans le blog
    51
    Par défaut
    Parce que c'est toujours la meme image qui est affichee peut-etre ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    static void displayImage1() {
            String displayImage1 = "src/photos/photo1.jpg";
            ImageIcon image1 = new ImageIcon(displayImage1);
            jLabelImages.setIcon(image1);
        }
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    Non ce n'est pas ça, le problème est le même si je supprime cette méthode que j'utilise juste pour afficher la première image à l'ouverture.

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    Une autre idée peut-être?

  5. #5
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 838
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 838
    Points : 22 846
    Points
    22 846
    Billets dans le blog
    51
    Par défaut
    Utiliser le débogueur pour vérifier que tu passes bien dans les portions de code qui changent l'image ? Exporter ces images vers des fichiers le disque pour vérifier que ce sont les bonnes qui ont été chargées par l'application ?
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    Oui j'ai bien vérifié avec le débuggeur, les fichiers sont bien créés dans le dossier (d'ailleurs je le vois en direct dans le dossier que j'affiche dans Windows), lorsque je sélectionne une autre id dans la liste jComboBoxNomCommun ou NomLatin, les images sont bien changées dans le dossier à chaque fois mais on dirait que ma méthode pour le diapo ne charge le jLabelImages qu'une seule fois et c'est pour ça que pour les autres sélections c'est les mêmes images de la 1ère sélection même si elles sont changées dans le dossier.
    Pourtant, je fais appel à la méthode imagesImportToList à chaque fois qu'une recherche est faite dans la liste.
    On dirait que c'est dans la méthode buttonsSlideShow que ça ne prend pas en compte les nouvelles images.

  7. #7
    Candidat au Club
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 7
    Points : 4
    Points
    4
    Par défaut
    J'ai finalement trouvé la solution, j'ai créé un objet ImageIcon pour chaque image générée dans le dossier src, j'ai donc rajouté cette ligne dans chacune des méthodes imageGenerate:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    image1 = new ImageIcon(ImageIO.read(new File("src/photos/photo1.jpg")));
    et préalablement ajouter en déclaration de variables:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        static ImageIcon image1;
        static ImageIcon image2;
        static ImageIcon image3;
        static ImageIcon image4;
        static ImageIcon image5;
    Voici le code pour la méthode image1Generate, il n'est plus nécessaire de créer les images dans un dossier:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    public void image1Generate() throws SQLException, IOException {
     
        Blob blob = rs.getBlob("image1");
     
        int blobLength = (int) blob.length();
     
        byte[] blobAsBytes = blob.getBytes(1, blobLength);
        final BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(blobAsBytes));
     
        image1 = (new ImageIcon(bufferedImage));
        }
    Puis j'ai modifié en conséquence la méthode imagesImportToList:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    public static void imagesImportToList() {
     
            s[0] = image1;
            s[1] = image2;
            s[2] = image3;
            s[3] = image4;
            s[4] = image5;
        }
    et pour finir, afin que mon diaporama ne s'emmêle pas les pinceaux et revenir à l'image1 à chaque changement , j'ai ajouté là où il était nécessaire: i = 0;

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 12/08/2013, 20h46
  2. Mise à jour d'une image dans JFrame
    Par nouraty dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 09/03/2012, 17h07
  3. Problème de mise à jour d'un champ dans bdd
    Par Tommy57 dans le forum VB.NET
    Réponses: 5
    Dernier message: 17/09/2010, 09h57
  4. [AC-2003] problème de mise à jour des champs disponibles dans TCD
    Par patbeautifulday dans le forum IHM
    Réponses: 3
    Dernier message: 03/03/2010, 09h59
  5. Réponses: 1
    Dernier message: 24/04/2006, 17h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo