Tableau d'images
Bonjour,
Je veux créer un tableau d'images que je pourrais récuperer pas la suite pour les faire défiler sur un JPanel à l'aide d'un bouton Suivant.
Voici des bouts de mon code:
static JLabel[] image = new JLabel[100];
static String rep = ".../Interface/Images/";
static String[] listNames = {"image1.png", "image2.png", "image3.png};
public void chargeImage(){
for(int i=0;i<=listNames.length;i++)
image[i] = new JLabel(new ImageIcon(rep + listNames[i]));
}
public void suivant() {
for(int i=0;i<=listNames.length;i++)
image[i].setIcon( (Icon) image[i+1]);
}
Mais quand je fais un test avec un " panel.add(image[0]) " je reçois une erreur. Pouvez vous m'aidez s'il vous plait, je ne comprend pas pourquoi ca ne marche pas?
Je veux créer un tableau d'images que je pourrais récuperer pas la suite pour les faire défiler sur un JPanel à l'aide d'un bouton Suivant.
Voici des bouts de mon code:
static JLabel[] image = new JLabel[100];
static String rep = ".../Interface/Images/";
static String[] listNames = {"image1.png", "image2.png", "image3.png};
public void chargeImage(){
for(int i=0;i<=listNames.length;i++)
image[i] = new JLabel(new ImageIcon(rep + listNames[i]));
}
public void suivant() {
for(int i=0;i<=listNames.length;i++)
image[i].setIcon( (Icon) image[i+1]);
}
Mais quand je fais un test avec un " panel.add(image[0]) " je reçois une erreur. Pouvez vous m'aidez s'il vous plait, je ne comprend pas pourquoi ca ne marche pas?
4 réponses
-
Salut,
c'est quoi l'erreur en question ? -
Voici l'erreur que j'obtiens:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Fenetre.buildContentPane(Fenetre.java:75)
at Fenetre.build(Fenetre.java:50)
at Fenetre.<init>(Fenetre.java:39)
at Fenetre$1.run(Fenetre.java:112)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source) -
ta variable panel est elle bien initialisé ?
-
Oui sans le 'panel.add(image[0])' ça marche très bien.